shithub: scc

Download patch

ref: e83f4e7c1597b0647aab5d8bd05cf8ef25a32e24
parent: 929f5e2ff45a91d85948ecd5583c0ff90958c218
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed May 27 08:10:34 EDT 2015

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.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -364,6 +364,10 @@
 	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 @@
 	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