[nasm:nasm-2.16.xx] preproc: handle empty expansion in %map

nasm-bot for H. Peter Anvin hpa at zytor.com
Mon Oct 16 01:27:04 PDT 2023


Commit-ID:  8584bce804ad957ed0530f8feb076200ce0e9ce4
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=8584bce804ad957ed0530f8feb076200ce0e9ce4
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Mon, 16 Oct 2023 01:24:20 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Mon, 16 Oct 2023 01:24:20 -0700

preproc: handle empty expansion in %map

%map(foo) should expand to the empty string, but instead crashed NASM.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 asm/preproc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/asm/preproc.c b/asm/preproc.c
index 08734d3c..013ab733 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -7449,7 +7449,6 @@ stdmac_map(const SMacro *s, Token **params, int nparam)
     if (nparam % mparams) {
         nasm_nonfatal("%s expected a multiple of %d expansion parameters, got %d\n",
                       s->name, mparams, nparam);
-        nparam -= nparam % mparams;
     }
 
     ctx = get_ctx(mname, &ctxname);
@@ -7460,6 +7459,9 @@ stdmac_map(const SMacro *s, Token **params, int nparam)
         return NULL;
     }
 
+    if (nparam < mparams)
+        return NULL;            /* Empty expansion */
+
     greedify = 0;
     if (unlikely(mparams > smac->nparam)) {
         if (smac->params[smac->nparam-1].flags & SPARM_GREEDY)
@@ -7493,7 +7495,7 @@ stdmac_map(const SMacro *s, Token **params, int nparam)
         }
 
         nparam -= mparams;
-        if (!nparam)
+        if (nparam < mparams)
             break;
 
         params += mparams;


More information about the Nasm-commits mailing list