scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e83f4e7c1597b0647aab5d8bd05cf8ef25a32e24
parent 929f5e2ff45a91d85948ecd5583c0ff90958c218
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 27 May 2015 12:10:34 +0200

Avoid trashing cpp symbols until be sure is correct

With the previous implementation, the status of the u.s field
could be corrupted, because it was freed, and it was not
put to NULL, and the symbol was still defined.
This new solution removes the problem don't looking the
symbol until be sure that the full #define directive
is correct, so it is impossible to have a wrong state.

Diffstat:
Mcc1/cpp.c | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -364,6 +364,10 @@ define(char *s) if (!iden(&s)) error("#define must have an identifier as parameter"); + for (t = s + strlen(s) + 1; isspace(*--t); *t = '\0') + /* nothing */; + s = mkdefine(s); + sym = lookup(NS_CPP); if ((sym->flags & ISDEFINED) && sym->ns == NS_CPP) { warn("'%s' redefined", yytext); @@ -372,10 +376,7 @@ define(char *s) sym->flags |= ISDEFINED; sym->ns = NS_CPP; sym->ctx = UCHAR_MAX; - - for (t = s + strlen(s) + 1; isspace(*--t); *t = '\0') - /* nothing */; - sym->u.s = mkdefine(s); + sym->u.s = s; } static void