Fix cpp.ansi crash when stringifying missing macro argument
Fixes https://github.com/davidgiven/ack/issues/238
This commit is contained in:
parent
afd6f30812
commit
3b1d440d5c
|
@ -706,32 +706,36 @@ 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, '"');
|
||||||
while (*p) {
|
|
||||||
if (is_wsp(*p)) {
|
|
||||||
if (!space) {
|
|
||||||
space = 1;
|
|
||||||
add2repl(repl, ' ');
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
space = 0;
|
|
||||||
|
|
||||||
if (!delim && (*p == '"' || *p == '\''))
|
if (p) {
|
||||||
delim = *p;
|
while (*p) {
|
||||||
else if (*p == delim && !backslash)
|
if (is_wsp(*p)) {
|
||||||
delim = 0;
|
if (!space) {
|
||||||
backslash = *p == '\\';
|
space = 1;
|
||||||
if (*p == '"' || (delim && *p == '\\'))
|
add2repl(repl, ' ');
|
||||||
add2repl(repl, '\\');
|
}
|
||||||
if (*p == TOKSEP || *p == NOEXPM) p++;
|
p++;
|
||||||
else add2repl(repl, *p++);
|
continue;
|
||||||
|
}
|
||||||
|
space = 0;
|
||||||
|
|
||||||
|
if (!delim && (*p == '"' || *p == '\''))
|
||||||
|
delim = *p;
|
||||||
|
else if (*p == delim && !backslash)
|
||||||
|
delim = 0;
|
||||||
|
backslash = *p == '\\';
|
||||||
|
if (*p == '"' || (delim && *p == '\\'))
|
||||||
|
add2repl(repl, '\\');
|
||||||
|
if (*p == TOKSEP || *p == NOEXPM) p++;
|
||||||
|
else add2repl(repl, *p++);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* trim spaces in the replacement list */
|
||||||
|
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--)
|
||||||
|
/* EMPTY */;
|
||||||
|
++repl->r_ptr; /* oops, one to far */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* trim spaces in the replacement list */
|
|
||||||
for (--repl->r_ptr; is_wsp(*repl->r_ptr); repl->r_ptr--)
|
|
||||||
/* EMPTY */;
|
|
||||||
++repl->r_ptr; /* oops, one to far */
|
|
||||||
add2repl(repl, '"');
|
add2repl(repl, '"');
|
||||||
} else
|
} else
|
||||||
error("illegal use of # operator");
|
error("illegal use of # operator");
|
||||||
|
|
Loading…
Reference in a new issue