ref: c01089f9b88ed71f3adcd21814216ea3dc262cf6
parent: 6c44531003e21a540421fc73a382d6f7b3520cbd
author: Roberto E. Vargas Caballero <[email protected]>
date: Sun Nov 16 22:56:33 EST 2014
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.
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -68,7 +68,9 @@
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 @@
}
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;
}