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@zytor.com>
This commit is contained in:
H. Peter Anvin 2023-10-16 01:24:20 -07:00
parent e10b7f902b
commit 8584bce804

View File

@ -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;