History

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.

Michael Matz committed 10 years ago

Commit 38e5cf01 parent 80804013 files · +10 −4Browse files

Unified · Split

3 files
  1. tccpp.c +5 −4
  2. tests/pp/16.c +3 −0
  3. tests/pp/16.expect +2 −0
tccpp.c+5−4
@@ -1280,17 +1280,18 @@ static int macro_is_equal(const int *a, const int *b) · 1279 unmodified lines
12801280 {
12811281 CValue cv;
12821282 int t;
1283+ static CString localbuf;
12831284
12841285 if (!a || !b)
12851286 return 1;
12861287
12871288 while (*a && *b) {
1288− /* first time preallocate static cstr_buf, next time only reset position to start */
1289− cstr_reset(&cstr_buf);
1289+ /* first time preallocate static localbuf, next time only reset position to start */
1290+ cstr_reset(&localbuf);
12901291 TOK_GET(&t, &a, &cv);
1291− cstr_cat(&cstr_buf, get_tok_str(t, &cv), 0);
1292+ cstr_cat(&localbuf, get_tok_str(t, &cv), 0);
12921293 TOK_GET(&t, &b, &cv);
1293− if (strcmp(cstr_buf.data, get_tok_str(t, &cv)))
1294+ if (strcmp(localbuf.data, get_tok_str(t, &cv)))
12941295 return 0;
12951296 }
12961297 return !(*a || *b);
tests/pp/16.c+3−0
@@ -0,0 +1,3 @@
1+/* The following should warn */
2+#define A ...
3+#define A <<=
tests/pp/16.expect+2−0
@@ -0,0 +1,2 @@
1+
2+16.c:3: warning: A redefined

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t