forked from Mirrors/tinycc
tccpp: Fix macro_is_equal
When tokens in macro definitions need cstr_buf inside get_tok_str, the second might overwrite the first (happens when tokens are multi-character non-identifiers, see testcase) in macro_is_equal, failing to diagnose a difference. Use a real local buffer.master
parent
8080401ab0
commit
38e5cf0983
9
tccpp.c
9
tccpp.c
|
@ -1280,17 +1280,18 @@ static int macro_is_equal(const int *a, const int *b)
|
||||||
{
|
{
|
||||||
CValue cv;
|
CValue cv;
|
||||||
int t;
|
int t;
|
||||||
|
static CString localbuf;
|
||||||
|
|
||||||
if (!a || !b)
|
if (!a || !b)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
while (*a && *b) {
|
while (*a && *b) {
|
||||||
/* first time preallocate static cstr_buf, next time only reset position to start */
|
/* first time preallocate static localbuf, next time only reset position to start */
|
||||||
cstr_reset(&cstr_buf);
|
cstr_reset(&localbuf);
|
||||||
TOK_GET(&t, &a, &cv);
|
TOK_GET(&t, &a, &cv);
|
||||||
cstr_cat(&cstr_buf, get_tok_str(t, &cv), 0);
|
cstr_cat(&localbuf, get_tok_str(t, &cv), 0);
|
||||||
TOK_GET(&t, &b, &cv);
|
TOK_GET(&t, &b, &cv);
|
||||||
if (strcmp(cstr_buf.data, get_tok_str(t, &cv)))
|
if (strcmp(localbuf.data, get_tok_str(t, &cv)))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return !(*a || *b);
|
return !(*a || *b);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
/* The following should warn */
|
||||||
|
#define A ...
|
||||||
|
#define A <<=
|
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
16.c:3: warning: A redefined
|
Loading…
Reference in New Issue