summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2009-03-24 06:33:32 +0000
committerPeter Johnson <peter@tortall.net>2009-03-24 06:33:32 +0000
commit338a832c3478deb9360bd5638a0201f5565a96a9 (patch)
treef6ee4d340bcccb61a9f03df07919aa70306a5418
parent73276e64a8b30973dbc141e9d0929c14351e58bd (diff)
downloadyasm-338a832c3478deb9360bd5638a0201f5565a96a9.tar.gz
Fix #155: Don't crash on missing %endmacro.
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
-rw-r--r--modules/preprocs/nasm/nasm-pp.c12
-rw-r--r--modules/preprocs/nasm/nasm-preproc.c3
-rw-r--r--modules/preprocs/nasm/tests/Makefile.inc2
-rw-r--r--modules/preprocs/nasm/tests/macroeof-err.asm1
-rw-r--r--modules/preprocs/nasm/tests/macroeof-err.errwarn1
5 files changed, 15 insertions, 4 deletions
diff --git a/modules/preprocs/nasm/nasm-pp.c b/modules/preprocs/nasm/nasm-pp.c
index 77865c4e..0bbb0f3a 100644
--- a/modules/preprocs/nasm/nasm-pp.c
+++ b/modules/preprocs/nasm/nasm-pp.c
@@ -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();
diff --git a/modules/preprocs/nasm/nasm-preproc.c b/modules/preprocs/nasm/nasm-preproc.c
index fa2b91e7..011831b4 100644
--- a/modules/preprocs/nasm/nasm-preproc.c
+++ b/modules/preprocs/nasm/nasm-preproc.c
@@ -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);
diff --git a/modules/preprocs/nasm/tests/Makefile.inc b/modules/preprocs/nasm/tests/Makefile.inc
index 6d7dcfb5..375316ac 100644
--- a/modules/preprocs/nasm/tests/Makefile.inc
+++ b/modules/preprocs/nasm/tests/Makefile.inc
@@ -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
index 00000000..dd51488b
--- /dev/null
+++ b/modules/preprocs/nasm/tests/macroeof-err.asm
@@ -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
index 00000000..c92f71e4
--- /dev/null
+++ b/modules/preprocs/nasm/tests/macroeof-err.errwarn
@@ -0,0 +1 @@
+-:1: error: end of file while still defining macro `foo'