aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tokenize.c
diff options
authorAlexander Viro <viro@parcelfarce.linux.theplanet.co.uk>2004-06-06 23:43:49 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:02:04 -0700
commita38e6db49e947820217f6398affe1fa840b72241 (patch)
tree1f047d7a2fcca9ba4681dce88302e8d0a3ba8087 /tokenize.c
parent65c3d3670f13293114e65f927e139dd54642c886 (diff)
downloadsparse-dev-a38e6db49e947820217f6398affe1fa840b72241.tar.gz
[PATCH] Fix preprocessor expansion anti-recursion properly
We taint identifiers when we are done with argument expansion; we untaint them when scan gets through the "untaint" token we leave right after the body of macro; we mark tokens noexpand in three situations: 1) when we copy a token marked noexpand; 2) when we get to expanding a token and see that its identifier is currently tainted; 3) when we scan for closing ) and see an identifier token with currently tainted identifier. That makes sure that by the time we get past the expanded body (and untaint the left-hand side of macro), all tokens bearing that identifier will be seen and marked noexpand. There is more elegant variant (it's practically straight from text of standard - set noexpand only in dup_token() and make it if (token_type(token) == TOKEN_IDENT) alloc->noexpand = token->noexpand | token->ident->tainted; which is as close as to transliteration of 6.10.3.4(2) as it gets), but before we can go for it, we need to sort out another problem - order of expansion/copying for arguments. So for now here's an equivalent heavier variant with a wart ((3) above) that works even with current expand_arguments() and when that gets sorted out we'll be able to get anti-recursion logics absolutely straightforward. And yes, it does preprocessor1.c correctly; it even get much subtler preprocessor7.c right.
Diffstat (limited to 'tokenize.c')
-rw-r--r--tokenize.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/tokenize.c b/tokenize.c
index b1867d25..2ed919cf 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -598,6 +598,7 @@ static struct ident *alloc_ident(const char *name, int len)
struct ident *ident = __alloc_ident(len);
ident->symbols = NULL;
ident->len = len;
+ ident->tainted = 0;
memcpy(ident->name, name, len);
return ident;
}