commit f1dec280f4eb0f7b7fd8ee90fc70b1cecebd0c47
parent 0b7c80e6d7c308b94d24d1eaf4ec0efc0938f16c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 10 Sep 2014 21:33:49 +0200
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.
Diffstat:
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/cc2/parser.c b/cc2/parser.c
@@ -80,48 +80,34 @@ Type l_uint64 = {
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];
}
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];
}
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];
}