From 32ea22537fa9802a94c284a71273b9a004cdb428 Mon Sep 17 00:00:00 2001
From: Luigi Scarso <luigi.scarso@gmail.com>
Date: Thu, 29 Sep 2022 14:06:51 +0000
Subject: [PATCH] fixed an infinite loop with --halt-on-error option (K.Berry)

[[Split portion of a mixed commit.]]
---
 source/texk/web2c/luatexdir/lua/luainit.c       | 1 +
 source/texk/web2c/luatexdir/luatex_svnversion.h | 2 +-
 source/texk/web2c/luatexdir/tex/errors.c        | 7 +++++++
 source/texk/web2c/luatexdir/tex/mainbody.c      | 4 ++++
 source/texk/web2c/luatexdir/tex/mainbody.h      | 1 +
 5 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/source/texk/web2c/luatexdir/lua/luainit.c b/source/texk/web2c/luatexdir/lua/luainit.c
index 5a86b5e06..35683fccc 100644
--- a/source/texk/web2c/luatexdir/lua/luainit.c
+++ b/source/texk/web2c/luatexdir/lua/luainit.c
@@ -962,6 +962,7 @@ void lua_initialize(int ac, char **av)
     interactionoption = 4;
     filelineerrorstylep = false;
     haltonerrorp = false;
+    haltingonerrorp = false;
     tracefilenames = 1;
     dump_name = NULL;
     /*tex
diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h
index 6809e8b9c..9821051cb 100644
--- a/source/texk/web2c/luatexdir/luatex_svnversion.h
+++ b/source/texk/web2c/luatexdir/luatex_svnversion.h
@@ -1,4 +1,4 @@
 #ifndef luatex_svn_revision_h
 #define luatex_svn_revision_h
-#define luatex_svn_revision 7539
+#define luatex_svn_revision 7540
 #endif
diff --git a/source/texk/web2c/luatexdir/tex/errors.c b/source/texk/web2c/luatexdir/tex/errors.c
index ce80df99e..01b6f44aa 100644
--- a/source/texk/web2c/luatexdir/tex/errors.c
+++ b/source/texk/web2c/luatexdir/tex/errors.c
@@ -436,6 +436,13 @@ void error(void)
         show_context();
     }
     if (haltonerrorp) {
+        /*tex If |close_files_and_terminate| generates an error, we'll end up back
+          here; just give up in that case. If files are truncated, too bad. */
+        if (haltingonerrorp) {
+          /*tex  quit immediately */
+          do_final_end ();
+        }
+        haltingonerrorp=true;
         history = fatal_error_stop;
         jump_out();
     }
diff --git a/source/texk/web2c/luatexdir/tex/mainbody.c b/source/texk/web2c/luatexdir/tex/mainbody.c
index 3d239b5a2..fd77be071 100644
--- a/source/texk/web2c/luatexdir/tex/mainbody.c
+++ b/source/texk/web2c/luatexdir/tex/mainbody.c
@@ -294,6 +294,10 @@ int filelineerrorstylep;
 
 int haltonerrorp;
 
+/*tex already trying to halt? */
+
+boolean haltingonerrorp; 
+
 /*tex current filename is quoted */
 
 boolean quoted_filename;
diff --git a/source/texk/web2c/luatexdir/tex/mainbody.h b/source/texk/web2c/luatexdir/tex/mainbody.h
index 6bb4e66fe..011b1958c 100644
--- a/source/texk/web2c/luatexdir/tex/mainbody.h
+++ b/source/texk/web2c/luatexdir/tex/mainbody.h
@@ -144,6 +144,7 @@ extern int expand_depth;
 /*extern int parsefirstlinep;*/
 extern int filelineerrorstylep;
 extern int haltonerrorp;
+extern boolean haltingonerrorp;
 extern boolean quoted_filename;
 
 extern int total_pages;
-- 
GitLab