[Nasm-commits] [nasm:nasm-2.15.xx] BR 3392662: handle empty argument at end of mmacro call

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Thu Jun 4 19:57:05 PDT 2020


Commit-ID:  f8639bdb52474ecabd7aba6ecaa3a70ea77a777d
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=f8639bdb52474ecabd7aba6ecaa3a70ea77a777d
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Thu, 4 Jun 2020 16:29:53 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Thu, 4 Jun 2020 16:29:53 -0700

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 at units.it>
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 asm/preproc.c | 13 ++++++++++---
 1 file 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;


More information about the Nasm-commits mailing list