commit f124441bbf6a16824334f195bb5bec268a55eefa
parent db2067f57cf7f2cf6ac71e28db1b77212a4a560c
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:
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;