From a715d7143d9d17da17e67fec6af1c01409a71a31 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 8 Apr 2014 22:19:48 +0800 Subject: Prevent ## to appear at start or end of macro --- tccpp.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tccpp.c') diff --git a/tccpp.c b/tccpp.c index 7144ee4..c8beec5 100644 --- a/tccpp.c +++ b/tccpp.c @@ -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); -- cgit v1.3.1