preproc: make sure the mmacro params list is NULL-terminated

If we adjust nparams due to default or greedy arguments, we need to
re-terminate the params[] array.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2019-08-20 16:24:46 -07:00
parent d4607846a4
commit 7eb18213b7

View File

@ -5138,7 +5138,6 @@ static MMacro *is_mmacro(Token * tline, int *nparamp, Token ***params_array)
memcpy(&params[nparam+1], &m->defaults[nparam+1-m->nparam_min], memcpy(&params[nparam+1], &m->defaults[nparam+1-m->nparam_min],
(newnparam - nparam) * sizeof(*params)); (newnparam - nparam) * sizeof(*params));
nparam = newnparam; nparam = newnparam;
params[nparam+1] = NULL;
} }
/* /*
* If we've gone over the maximum parameter count (and * If we've gone over the maximum parameter count (and
@ -5148,6 +5147,12 @@ static MMacro *is_mmacro(Token * tline, int *nparamp, Token ***params_array)
if (m->plus && nparam > m->nparam_max) if (m->plus && nparam > m->nparam_max)
nparam = m->nparam_max; nparam = m->nparam_max;
/*
* If nparam was adjusted above, make sure the list is still
* NULL-terminated.
*/
params[nparam+1] = NULL;
/* Done! */ /* Done! */
*params_array = params; *params_array = params;
*nparamp = nparam; *nparamp = nparam;