shithub: scc

Download patch

ref: 27f24349d56b76da526aa232dbb686ad792a055a
parent: 408069b686f5db03f2ede95ef7e703ce40b8d3ff
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Mar 14 15:48:18 EDT 2022

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.

--- 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 @@
 			symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
 		freesym(sym);
 	}
-	curlocal = locals = NULL;
+	locals = NULL;
 }
 
 Symbol *
@@ -74,11 +74,8 @@
 	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;