scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 27f24349d56b76da526aa232dbb686ad792a055a
parent 408069b686f5db03f2ede95ef7e703ce40b8d3ff
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 14 Mar 2022 19:48:18 +0100

cc2: Fix popctx()

The list of locals was not created correctly and only the first
local was freed() but the hashtable was modified like if all
the symbols were freed.

Diffstat:
Msrc/cmd/cc/cc2/symbol.c | 11++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/cmd/cc/cc2/symbol.c b/src/cmd/cc/cc2/symbol.c @@ -11,7 +11,7 @@ Symbol *locals; -static Symbol *symtab[NR_SYMHASH], *curlocal; +static Symbol *symtab[NR_SYMHASH]; static int infunction; @@ -51,7 +51,7 @@ popctx(void) symtab[sym->id & NR_SYMHASH-1] = sym->h_next; freesym(sym); } - curlocal = locals = NULL; + locals = NULL; } Symbol * @@ -74,11 +74,8 @@ getsym(unsigned id) sym = xcalloc(1, sizeof(*sym)); sym->id = id; if (infunction) { - if (!locals) - locals = sym; - if (curlocal) - curlocal->next = sym; - curlocal = sym; + sym->next = locals; + locals = sym; } if (id != TMPSYM) { sym->h_next = *htab;