Fix cpp.ansi crash when stringifying missing macro argument

Fixes https://github.com/davidgiven/ack/issues/238
This commit is contained in:
tkchia 2022-08-02 15:28:21 +00:00
parent afd6f30812
commit 3b1d440d5c

View file

@ -706,6 +706,8 @@ static char *stringify(
assert(n != 0); assert(n != 0);
p = args->a_rawvec[n-1]; p = args->a_rawvec[n-1];
add2repl(repl, '"'); add2repl(repl, '"');
if (p) {
while (*p) { while (*p) {
if (is_wsp(*p)) { if (is_wsp(*p)) {
if (!space) { if (!space) {
@ -732,6 +734,8 @@ static char *stringify(
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--) for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--)
/* EMPTY */; /* EMPTY */;
++repl->r_ptr; /* oops, one to far */ ++repl->r_ptr; /* oops, one to far */
}
add2repl(repl, '"'); add2repl(repl, '"');
} else } else
error("illegal use of # operator"); error("illegal use of # operator");