shithub: scc

Download patch

ref: 6408599f6398af4a1c0913c1ee8b1e63c4e4fb4a
parent: e2b1e124e7694cad72c120ae3b7eea8dbb26f4d8
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri May 27 13:08:32 EDT 2016

[cc1] Remove undefined behaviour in specifier

Variables local to loops are created and destroy in every iteration
of the loop, and it means that they (logically) does not retain
the value from the previous iteration. In the case of long long
we were using the value of the previous iteration (the iteration
of the first long), and it was working because moderm compilers
does not create/destroy the variables in this case. It was possible
to create strange results with something like:

	long int long

because in this case p was pointing to type and not to the size.
This patch fixes the problem setting the value of p to NULL in
every iteration and explicitily setting the value of p in the case
of long long. If the value of p is not set to the correct value
we will have a segmentation fault and e will discover the error
as soon as possible.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -371,7 +371,7 @@
 	spec = qlf = sign = type = cls = size = 0;
 
 	for (;;) {
-		unsigned *p;
+		unsigned *p = NULL;
 		Type *(*dcl)(void) = NULL;
 
 		switch (yytoken) {
@@ -415,7 +415,6 @@
 				if (size == LONG) {
 					yylval.token = LLONG;
 					size = 0;
-					break;
 				}
 			case SHORT:
 				p = &size;