commit bc267b974204cd6ddf6f717a0a2597dc33f68406
Author:     Quentin Rameau <[email protected]>
AuthorDate: Thu Oct 27 14:17:40 2016 +0200
Commit:     Quentin Rameau <[email protected]>
CommitDate: Thu Nov 3 11:45:55 2016 +0100

    [cc2] fix symbol hashing of TMPSYM
    
    As TMPSYM is a dummy id, we would always use the same hash for temporary
    symbols ending up in a segfault or infinite loop.
    
    Thanks to k0ga for finding a better fix than mine.

diff --git a/cc2/symbol.c b/cc2/symbol.c
index 9b1fdbc..3c0723c 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -38,7 +38,8 @@ popctx(void)
        infunction = 0;
        for (sym = locals; sym; sym = next) {
                next = sym->next;
-               symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
+               if (sym->id != TMPSYM)
+                       symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
                freesym(sym);
        }
        curlocal = locals = NULL;
@@ -70,8 +71,10 @@ getsym(unsigned id)
                                curlocal->next = sym;
                        curlocal = sym;
                }
-               sym->h_next = *htab;
-               *htab = sym;
+               if (id != TMPSYM) {
+                       sym->h_next = *htab;
+                       *htab = sym;
+               }
        }
        return sym;
 }

Reply via email to