From b83b9825f81e99414df95b000df0fd47d55004aa Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 17 Aug 2020 17:04:23 +0200 Subject: [PATCH] Fix _NARG crashing outside of macros And add a test for it --- src/asm/symbol.c | 4 ++++ test/asm/narg-nosect.asm | 1 + test/asm/narg-nosect.err | 3 +++ test/asm/narg-nosect.out | 1 + 4 files changed, 9 insertions(+) create mode 100644 test/asm/narg-nosect.asm create mode 100644 test/asm/narg-nosect.err create mode 100644 test/asm/narg-nosect.out diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 45bbb967..f1f622dd 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -77,6 +77,10 @@ void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg) static int32_t Callback_NARG(void) { + if (!macro_GetCurrentArgs()) { + yyerror("_NARG does not make sense outside of a macro"); + return 0; + } return macro_NbArgs(); } diff --git a/test/asm/narg-nosect.asm b/test/asm/narg-nosect.asm new file mode 100644 index 00000000..54099434 --- /dev/null +++ b/test/asm/narg-nosect.asm @@ -0,0 +1 @@ + PRINTT "{_NARG}\n" diff --git a/test/asm/narg-nosect.err b/test/asm/narg-nosect.err new file mode 100644 index 00000000..918c3b11 --- /dev/null +++ b/test/asm/narg-nosect.err @@ -0,0 +1,3 @@ +ERROR: narg-nosect.asm(1): + _NARG does not make sense outside of a macro +error: Assembly aborted (1 errors)! diff --git a/test/asm/narg-nosect.out b/test/asm/narg-nosect.out new file mode 100644 index 00000000..ebfabbe4 --- /dev/null +++ b/test/asm/narg-nosect.out @@ -0,0 +1 @@ +$0