shithub: scc

Download patch

ref: c301d4451f6034fc462c8b852c1ba2e397a7892c
parent: 03ede7d69465d1ee44d12078a3c880a28cc75534
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Aug 8 14:58:35 EDT 2014

Fix local() and global() allocation bug

The number of records were not stored in the variables for them,
so the allocation was always done, generating a segmentation fault
in some cases.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -76,8 +76,10 @@
 
 	if (i >= NR_INT_IDENT)
 		error(EINTNUM);
-	if (i >= nr)
-		localtbl = xrealloc(localtbl, i+1);
+	if (i > nr) {
+		nr = i + 5;
+		localtbl = xrealloc(localtbl, nr);
+	}
 	return &localtbl[i];
 }
 
@@ -89,8 +91,10 @@
 
 	if (i >= NR_EXT_IDENT)
 		error(EEXTNUM);
-	if (i >= nr)
-		globaltbl = xrealloc(globaltbl, i+1);
+	if (i >= nr) {
+		nr = i + 5;
+		globaltbl = xrealloc(globaltbl, nr);
+	}
 	return &globaltbl[i];
 }