scc

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

commit c01089f9b88ed71f3adcd21814216ea3dc262cf6
parent 6c44531003e21a540421fc73a382d6f7b3520cbd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 17 Nov 2014 03:56:33 -0500

Fix creation of data type in functions and structures

There were different reasons why this creation was incorrect in both
cases. In the case of structs we were decrementing the number of
elements, when it was correct, and this create very big numbers
in the case of 0 elements. In the case of the functions the problem
was the ternary operator, that is not neeeded at all, because we already
check that the number of elements is bigger than 0.

Diffstat:
cc1/decl.c | 13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -68,7 +68,9 @@ fundcl(struct dcldata *dp) expect(')'); if (n != 0) { siz = sizeof(*tp) * n; - tp = (siz > 0) ? memcpy(xmalloc(siz), pars, siz) : NULL; + tp = memcpy(xmalloc(siz), pars, siz); + } else { + tp = NULL; } if (yytoken != '{') { @@ -350,10 +352,11 @@ structdcl(void) } emitestruct(); - n = bp - buff - 1; - siz = sizeof(Type *) * n; - tagtype->n.elem = n; - tagtype->pars = memcpy(xmalloc(siz), buff, siz); + if ((n = bp - buff) != 0) { + siz = sizeof(Type *) * n; + tagtype->n.elem = n; + tagtype->pars = memcpy(xmalloc(siz), buff, siz); + } return tagtype; }