summaryrefslogtreecommitdiff
path: root/asm/preproc.c
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2020-06-04 16:29:53 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2020-06-04 16:29:53 -0700
commitf8639bdb52474ecabd7aba6ecaa3a70ea77a777d (patch)
tree684780315d1b6b7c2c93b49b95ff2aaddb0d675d /asm/preproc.c
parent283bc92a92b71904ee7d3769ea94e452ee353178 (diff)
downloadnasm-f8639bdb52474ecabd7aba6ecaa3a70ea77a777d.tar.gz
BR 3392662: handle empty argument at end of mmacro call
A trailing comma at the end of an mmacro call is an empty argument, and so we can't terminate the argument-processing loop. The only case where skip_white() returning NULL where we are allowed to terminate the loop is in the case of nparams == 0, i.e. the macro call has no arguments at all. Reported-by: gabriele balducci <balducci@units.it> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'asm/preproc.c')
-rw-r--r--asm/preproc.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/asm/preproc.c b/asm/preproc.c
index 83a61b42..414a9724 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -2354,7 +2354,11 @@ static void count_mmac_params(Token * t, int *nparamp, Token ***paramsp)
params = nasm_malloc(paramsize * sizeof(*params));
params[0] = NULL;
- while ((t = skip_white(t))) {
+ while (true) {
+ t = skip_white(t);
+ if (!t && !nparam)
+ break; /* No arguments */
+
/* 2 slots for captured label and NULL */
if (nparam+2 >= paramsize) {
paramsize += PARAM_DELTA;
@@ -2381,11 +2385,14 @@ static void count_mmac_params(Token * t, int *nparamp, Token ***paramsp)
}
}
+ /* Advance to the next comma */
while (tok_isnt(t, ','))
t = t->next;
- if (t) /* got a comma */
- t = t->next; /* eat the comma */
+ if (!t)
+ break; /* End of line */
+
+ t = t->next; /* Eat the comma, start over */
}
params[nparam+1] = NULL;