Fix _NARG crashing outside of macros

And add a test for it
This commit is contained in:
ISSOtm
2020-08-17 17:04:23 +02:00
parent d641972cde
commit b83b9825f8
4 changed files with 9 additions and 0 deletions

View File

@@ -77,6 +77,10 @@ void sym_ForEach(void (*func)(struct Symbol *, void *), void *arg)
static int32_t Callback_NARG(void) static int32_t Callback_NARG(void)
{ {
if (!macro_GetCurrentArgs()) {
yyerror("_NARG does not make sense outside of a macro");
return 0;
}
return macro_NbArgs(); return macro_NbArgs();
} }

1
test/asm/narg-nosect.asm Normal file
View File

@@ -0,0 +1 @@
PRINTT "{_NARG}\n"

3
test/asm/narg-nosect.err Normal file
View File

@@ -0,0 +1,3 @@
ERROR: narg-nosect.asm(1):
_NARG does not make sense outside of a macro
error: Assembly aborted (1 errors)!

1
test/asm/narg-nosect.out Normal file
View File

@@ -0,0 +1 @@
$0