]> granicus.if.org Git - yasm/commitdiff
Fix #155: Don't crash on missing %endmacro.
authorPeter Johnson <peter@tortall.net>
Tue, 24 Mar 2009 06:33:32 +0000 (06:33 -0000)
committerPeter Johnson <peter@tortall.net>
Tue, 24 Mar 2009 06:33:32 +0000 (06:33 -0000)
We were crashing because we didn't generate this error until the preproc
module was getting cleaned up, which doesn't happen until after linemap
is cleaned up.  Instead detect and output this error when we reach the end
of preprocessed tokens during the parsing stage.

svn path=/trunk/yasm/; revision=2185

modules/preprocs/nasm/nasm-pp.c
modules/preprocs/nasm/nasm-preproc.c
modules/preprocs/nasm/tests/Makefile.inc
modules/preprocs/nasm/tests/macroeof-err.asm [new file with mode: 0644]
modules/preprocs/nasm/tests/macroeof-err.errwarn [new file with mode: 0644]

index 77865c4e4f4079d5c12dbe7f144aa46ba753c758..0bbb0f3aca665be85a2eadbb58c169cd912b1730 100644 (file)
@@ -5017,11 +5017,15 @@ pp_cleanup(int pass_)
 {
     int h;
 
-    if (defining)
+    if (pass_ == 1)
     {
-        error(ERR_NONFATAL, "end of file while still defining macro `%s'",
-                defining->name);
-        free_mmacro(defining);
+        if (defining)
+        {
+            error(ERR_NONFATAL, "end of file while still defining macro `%s'",
+                    defining->name);
+            free_mmacro(defining);
+        }
+        return;
     }
     while (cstk)
         ctx_pop();
index fa2b91e7930344bc9ecf4cf61211109c3239379a..011831b4ae6f15f53509d6a80fb4faf6ad9b305d 100644 (file)
@@ -195,7 +195,10 @@ nasm_preproc_get_line(yasm_preproc *preproc)
 
     line = nasmpp.getline();
     if (!line)
+    {
+        nasmpp.cleanup(1);
         return NULL;    /* EOF */
+    }
 
     linnum = preproc_nasm->prior_linnum += preproc_nasm->lineinc;
     altline = nasm_src_get(&linnum, &preproc_nasm->file_name);
index 6d7dcfb55bd835f84e1add1af1172d40a60fb680..375316ac086a449b8ac44a37de20f21fd116e705 100644 (file)
@@ -9,6 +9,8 @@ EXTRA_DIST += modules/preprocs/nasm/tests/ifcritical-err.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/ifcritical-err.errwarn
 EXTRA_DIST += modules/preprocs/nasm/tests/longline.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/longline.hex
+EXTRA_DIST += modules/preprocs/nasm/tests/macroeof-err.asm
+EXTRA_DIST += modules/preprocs/nasm/tests/macroeof-err.errwarn
 EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.errwarn
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.asm
diff --git a/modules/preprocs/nasm/tests/macroeof-err.asm b/modules/preprocs/nasm/tests/macroeof-err.asm
new file mode 100644 (file)
index 0000000..dd51488
--- /dev/null
@@ -0,0 +1 @@
+%macro foo 0
diff --git a/modules/preprocs/nasm/tests/macroeof-err.errwarn b/modules/preprocs/nasm/tests/macroeof-err.errwarn
new file mode 100644 (file)
index 0000000..c92f71e
--- /dev/null
@@ -0,0 +1 @@
+-:1: error: end of file while still defining macro `foo'