aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-05-18 20:36:59 +0200
committerMichael Matz <matz@suse.de>2016-12-15 17:47:05 +0100
commit38e5cf0983e02b2fc77d77adfd9b937768dfcfd5 (patch)
treefd09ead1876e9bc967ebf71698449fe759f395e7 /tccpp.c
parent8080401ab00aea30a1df70e36b55d3ff745d00c8 (diff)
downloadtinycc-38e5cf0983e02b2fc77d77adfd9b937768dfcfd5.tar.gz
tinycc-38e5cf0983e02b2fc77d77adfd9b937768dfcfd5.tar.bz2
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.
Diffstat (limited to 'tccpp.c')
-rw-r--r--tccpp.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/tccpp.c b/tccpp.c
index ebbd051..6446c9c 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1280,17 +1280,18 @@ static int macro_is_equal(const int *a, const int *b)
{
CValue cv;
int t;
+ static CString localbuf;
if (!a || !b)
return 1;
while (*a && *b) {
- /* first time preallocate static cstr_buf, next time only reset position to start */
- cstr_reset(&cstr_buf);
+ /* first time preallocate static localbuf, next time only reset position to start */
+ cstr_reset(&localbuf);
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);
- if (strcmp(cstr_buf.data, get_tok_str(t, &cv)))
+ if (strcmp(localbuf.data, get_tok_str(t, &cv)))
return 0;
}
return !(*a || *b);