mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-28 04:00:06 +08:00
Prevent ## to appear at start or end of macro
This commit is contained in:
parent
91d4db600b
commit
a715d7143d
14
tccpp.c
14
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);
|
||||
|
2
tests/tests2/65_macro_concat_start.c
Normal file
2
tests/tests2/65_macro_concat_start.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define paste(A,B) ##A B
|
||||
paste(x,y)
|
1
tests/tests2/65_macro_concat_start.expect
Normal file
1
tests/tests2/65_macro_concat_start.expect
Normal file
@ -0,0 +1 @@
|
||||
65_macro_concat_start.c:1: error: '##' invalid at start of macro
|
2
tests/tests2/66_macro_concat_end.c
Normal file
2
tests/tests2/66_macro_concat_end.c
Normal file
@ -0,0 +1,2 @@
|
||||
#define paste(A,B) A B##
|
||||
paste(x,y)
|
1
tests/tests2/66_macro_concat_end.expect
Normal file
1
tests/tests2/66_macro_concat_end.expect
Normal file
@ -0,0 +1 @@
|
||||
66_macro_concat_end.c:2: error: '##' invalid at end of macro
|
@ -79,7 +79,9 @@ TESTS = \
|
||||
61_undefined_enum.test \
|
||||
62_enumerator_redefinition.test \
|
||||
63_local_enumerator_redefinition.test \
|
||||
64_macro_nesting.test
|
||||
64_macro_nesting.test \
|
||||
65_macro_concat_start.test \
|
||||
66_macro_concat_end.test
|
||||
|
||||
# 30_hanoi.test -- seg fault in the code, gcc as well
|
||||
# 34_array_assignment.test -- array assignment is not in C standard
|
||||
|
Loading…
Reference in New Issue
Block a user