From 69c2e7f96c95ba088657ce8bb9754c12c3e89397 Mon Sep 17 00:00:00 2001 From: grischka Date: Wed, 24 Jul 2013 17:06:13 +0200 Subject: [PATCH] tccgen: fix crash with undeclared struct ... as in: #include int main() { struct asdasd x; printf("%d\n", sizeof(x)); } This fixes commit 17571298f30bf204fafe9cf1aca5258d2d087d63 --- tccgen.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tccgen.c b/tccgen.c index 14a5a54c..4849b6c0 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);