scc

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

commit 541fffb698465fbdb961b0212fdfe22f484bacf9
parent 2d3c0c4b70e668183723e5274e7ae01c6678a704
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 27 May 2016 17:08:32 +0200

[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.

Diffstat:
Mcc1/decl.c | 3+--
1 file changed, 1 insertion(+), 2 deletions(-)

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