commit 541fffb698465fbdb961b0212fdfe22f484bacf9
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Fri May 27 17:08:32 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri May 27 17:08:32 2016 +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.

diff --git a/cc1/decl.c b/cc1/decl.c
index c77238e..0bffb41 100644
--- 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;

Reply via email to