scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 60f62db06595ad07503f3a587607d466c0d460a0
parent 06fffa554b4c6d04b37f148160c81c7e840c7601
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  9 Sep 2014 17:07:11 +0200

Fix bug in Symbol allocation in cc2

We were allocating using only the number of elements, and not the
size of each element, so at the end we were writing after the end
of the array.

Diffstat:
Mcc2/parser.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cc2/parser.c b/cc2/parser.c @@ -84,8 +84,8 @@ local(char *num) if (i >= NR_INT_IDENT) error(EINTNUM); if (i > nr) { - nr = i + 5; - localtbl = xrealloc(localtbl, nr); + nr = i + 50; + localtbl = xrealloc(localtbl, nr * sizeof(Symbol)); } return &localtbl[i]; } @@ -99,8 +99,8 @@ global(char *num) if (i >= NR_EXT_IDENT) error(EEXTNUM); if (i >= nr) { - nr = i + 5; - globaltbl = xrealloc(globaltbl, nr); + nr = i + 50; + globaltbl = xrealloc(globaltbl, nr * sizeof(Symbol)); } return &globaltbl[i]; }