aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
diff options
context:
space:
mode:
authorgrischka <grischka>2013-07-24 17:06:13 +0200
committergrischka <grischka>2013-07-24 17:06:13 +0200
commit69c2e7f96c95ba088657ce8bb9754c12c3e89397 (patch)
tree0a546c8445dc6c747b0de54c34110471c21311e7 /tccgen.c
parent8c033a1461b743238bbfbc1bb8ef55909378f284 (diff)
downloadtinycc-69c2e7f96c95ba088657ce8bb9754c12c3e89397.tar.gz
tinycc-69c2e7f96c95ba088657ce8bb9754c12c3e89397.tar.bz2
tccgen: fix crash with undeclared struct
... as in: #include<stdio.h> int main() { struct asdasd x; printf("%d\n", sizeof(x)); } This fixes commit 17571298f30bf204fafe9cf1aca5258d2d087d63
Diffstat (limited to 'tccgen.c')
-rw-r--r--tccgen.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/tccgen.c b/tccgen.c
index 14a5a54..4849b6c 100644
--- a/tccgen.c
+++ b/tccgen.c
@@ -2764,6 +2764,7 @@ static void struct_decl(CType *type, int u)
v = anon_sym++;
}
type1.t = a;
+ type1.ref = NULL;
/* we put an undefined size for struct/union */
s = sym_push(v | SYM_STRUCT, &type1, 0, -1);
s->r = 0; /* default alignment is zero as gcc */
@@ -5337,12 +5338,13 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
flexible_array = NULL;
if ((type->t & VT_BTYPE) == VT_STRUCT) {
- Sym *field;
- field = type->ref;
- while (field && field->next)
- field = field->next;
- if (field->type.t & VT_ARRAY && field->type.ref->c < 0)
- flexible_array = field;
+ Sym *field = type->ref->next;
+ if (field) {
+ while (field->next)
+ field = field->next;
+ if (field->type.t & VT_ARRAY && field->type.ref->c < 0)
+ flexible_array = field;
+ }
}
size = type_size(type, &align);