aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
diff options
context:
space:
mode:
authorJoe Soroka <gits@joesoroka.com>2011-07-08 02:51:06 -0700
committerJoe Soroka <gits@joesoroka.com>2011-07-08 02:51:06 -0700
commit38756b506f99454a70402c2589a93e8a9d9d78c6 (patch)
treeb3b3d2d33cc8f55150b9e4e3fedad484a81c722e /tccpp.c
parent5cf5871aafa0032ec54fc76b11c06f2217409e46 (diff)
downloadtinycc-38756b506f99454a70402c2589a93e8a9d9d78c6.tar.gz
tinycc-38756b506f99454a70402c2589a93e8a9d9d78c6.tar.bz2
fix self-referential token pasting
Diffstat (limited to 'tccpp.c')
-rw-r--r--tccpp.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/tccpp.c b/tccpp.c
index 33c65a4..779aa42 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -2788,7 +2788,7 @@ static inline int *macro_twosharps(const int *macro_str)
CValue cval;
TokenString macro_str1;
CString cstr;
- int n;
+ int n, start_of_nosubsts;
/* we search the first '##' */
for(ptr = macro_str;;) {
@@ -2801,6 +2801,7 @@ static inline int *macro_twosharps(const int *macro_str)
}
/* we saw '##', so we need more processing to handle it */
+ start_of_nosubsts = -1;
tok_str_new(&macro_str1);
for(ptr = macro_str;;) {
TOK_GET(&tok, &ptr, &tokc);
@@ -2808,8 +2809,17 @@ static inline int *macro_twosharps(const int *macro_str)
break;
if (tok == TOK_TWOSHARPS)
continue;
+ if (tok == TOK_NOSUBST && start_of_nosubsts < 0)
+ start_of_nosubsts = macro_str1.len;
while (*ptr == TOK_TWOSHARPS) {
- do { t = *++ptr; } while (t == TOK_NOSUBST);
+ /* given 'a##b', remove nosubsts preceding 'a' */
+ if (start_of_nosubsts >= 0)
+ macro_str1.len = start_of_nosubsts;
+ /* given 'a##b', skip '##' */
+ t = *++ptr;
+ /* given 'a##b', remove nosubsts preceding 'b' */
+ while (t == TOK_NOSUBST)
+ t = *++ptr;
if (t && t != TOK_TWOSHARPS) {
TOK_GET(&t, &ptr, &cval);
@@ -2835,6 +2845,8 @@ static inline int *macro_twosharps(const int *macro_str)
cstr_reset(&cstr);
}
}
+ if (tok != TOK_NOSUBST)
+ start_of_nosubsts = -1;
tok_str_add2(&macro_str1, tok, &tokc);
}
tok_str_add(&macro_str1, 0);