Prevent ## to appear at start or end of macro

This commit is contained in:
Thomas Preud'homme
2014-04-08 22:19:48 +08:00
parent 91d4db600b
commit a715d7143d
6 changed files with 20 additions and 4 deletions

14
tccpp.c
View File

@ -1213,9 +1213,9 @@ static void tok_print(int *str)
ST_FUNC void parse_define(void)
{
Sym *s, *first, **ps;
int v, t, varg, is_vaargs, spc;
int v, t, varg, is_vaargs, spc, ptok, macro_list_start;
TokenString str;
v = tok;
if (v < TOK_IDENT)
tcc_error("invalid macro name '%s'", get_tok_str(tok, &tokc));
@ -1254,8 +1254,13 @@ ST_FUNC void parse_define(void)
tok_str_new(&str);
spc = 2;
/* EOF testing necessary for '-D' handling */
ptok = 0;
macro_list_start = 1;
while (tok != TOK_LINEFEED && tok != TOK_EOF) {
/* remove spaces around ## and after '#' */
if (!macro_list_start && spc == 2 && tok == TOK_TWOSHARPS)
tcc_error("'##' invalid at start of macro");
ptok = tok;
/* remove spaces around ## and after '#' */
if (TOK_TWOSHARPS == tok) {
if (1 == spc)
--str.len;
@ -1268,7 +1273,10 @@ ST_FUNC void parse_define(void)
tok_str_add2(&str, tok, &tokc);
skip:
next_nomacro_spc();
macro_list_start = 0;
}
if (ptok == TOK_TWOSHARPS)
tcc_error("'##' invalid at end of macro");
if (spc == 1)
--str.len; /* remove trailing space */
tok_str_add(&str, 0);