scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit c301d4451f6034fc462c8b852c1ba2e397a7892c
parent 03ede7d69465d1ee44d12078a3c880a28cc75534
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri,  8 Aug 2014 18:58:35 +0200

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.

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

diff --git a/cc2/parser.c b/cc2/parser.c @@ -76,8 +76,10 @@ local(char *num) 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 @@ global(char *num) 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]; }