diff options
| author | grischka <grischka> | 2013-07-24 17:06:13 +0200 |
|---|---|---|
| committer | grischka <grischka> | 2013-07-24 17:06:13 +0200 |
| commit | 69c2e7f96c95ba088657ce8bb9754c12c3e89397 (patch) | |
| tree | 0a546c8445dc6c747b0de54c34110471c21311e7 | |
| parent | 8c033a1461b743238bbfbc1bb8ef55909378f284 (diff) | |
| download | tinycc-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
| -rw-r--r-- | tccgen.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -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); |
