shithub: scc

Download patch

ref: f1dec280f4eb0f7b7fd8ee90fc70b1cecebd0c47
parent: 0b7c80e6d7c308b94d24d1eaf4ec0efc0938f16c
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 10 17:33:49 EDT 2014

Remove realloc of cc2

These realloc was incorrect because we were storing pointers
to the buffer returned by it, so it means that in some moment
the buffer could change of size and then the pointers became
invalid. This is a first solution (simple) that can be changed
later.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -80,16 +80,11 @@
 static Symbol *
 parameter(char *num)
 {
-	static Symbol *tbl;
+	static Symbol tbl[NR_FUNPARAM];
 	unsigned i = atoi(num);
-	static unsigned nr;
 
 	if (i >= NR_FUNPARAM)
 		error(EPARNUM);
-	if (i > nr) {
-		nr = i + 50;
-		tbl = xrealloc(tbl, nr * sizeof(Symbol));
-	}
 	return &tbl[i];
 }
 
@@ -96,16 +91,11 @@
 static Symbol *
 local(char *num)
 {
-	static Symbol *tbl;
+	static Symbol tbl[NR_INT_IDENT];
 	unsigned i = atoi(num);
-	static unsigned nr;
 
 	if (i >= NR_INT_IDENT)
 		error(EINTNUM);
-	if (i > nr) {
-		nr = i + 50;
-		tbl = xrealloc(tbl, nr * sizeof(Symbol));
-	}
 	return &tbl[i];
 }
 
@@ -112,16 +102,12 @@
 static Symbol *
 global(char *num)
 {
-	static Symbol *tbl;
+	static Symbol tbl[NR_EXT_IDENT];
 	unsigned i = atoi(num);
-	static unsigned nr;
 
 	if (i >= NR_EXT_IDENT)
 		error(EEXTNUM);
-	if (i >= nr) {
-		nr = i + 50;
-		tbl = xrealloc(tbl, nr * sizeof(Symbol));
-	}
+
 	return &tbl[i];
 }