From 338a832c3478deb9360bd5638a0201f5565a96a9 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 24 Mar 2009 06:33:32 +0000 Subject: [PATCH] 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 --- modules/preprocs/nasm/nasm-pp.c | 12 ++++++++---- modules/preprocs/nasm/nasm-preproc.c | 3 +++ modules/preprocs/nasm/tests/Makefile.inc | 2 ++ modules/preprocs/nasm/tests/macroeof-err.asm | 1 + modules/preprocs/nasm/tests/macroeof-err.errwarn | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 modules/preprocs/nasm/tests/macroeof-err.asm create mode 100644 modules/preprocs/nasm/tests/macroeof-err.errwarn 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' -- 2.40.0