mirror of
https://github.com/frida/tinycc
synced 2024-11-28 02:29:38 +03:00
tccgen: fix crash with undeclared struct
... as in:
#include<stdio.h>
int main()
{
struct asdasd x;
printf("%d\n", sizeof(x));
}
This fixes commit 17571298f3
This commit is contained in:
parent
8c033a1461
commit
69c2e7f96c
8
tccgen.c
8
tccgen.c
@ -2764,6 +2764,7 @@ static void struct_decl(CType *type, int u)
|
|||||||
v = anon_sym++;
|
v = anon_sym++;
|
||||||
}
|
}
|
||||||
type1.t = a;
|
type1.t = a;
|
||||||
|
type1.ref = NULL;
|
||||||
/* we put an undefined size for struct/union */
|
/* we put an undefined size for struct/union */
|
||||||
s = sym_push(v | SYM_STRUCT, &type1, 0, -1);
|
s = sym_push(v | SYM_STRUCT, &type1, 0, -1);
|
||||||
s->r = 0; /* default alignment is zero as gcc */
|
s->r = 0; /* default alignment is zero as gcc */
|
||||||
@ -5337,13 +5338,14 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
|||||||
|
|
||||||
flexible_array = NULL;
|
flexible_array = NULL;
|
||||||
if ((type->t & VT_BTYPE) == VT_STRUCT) {
|
if ((type->t & VT_BTYPE) == VT_STRUCT) {
|
||||||
Sym *field;
|
Sym *field = type->ref->next;
|
||||||
field = type->ref;
|
if (field) {
|
||||||
while (field && field->next)
|
while (field->next)
|
||||||
field = field->next;
|
field = field->next;
|
||||||
if (field->type.t & VT_ARRAY && field->type.ref->c < 0)
|
if (field->type.t & VT_ARRAY && field->type.ref->c < 0)
|
||||||
flexible_array = field;
|
flexible_array = field;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size = type_size(type, &align);
|
size = type_size(type, &align);
|
||||||
/* If unknown size, we must evaluate it before
|
/* If unknown size, we must evaluate it before
|
||||||
|
Loading…
Reference in New Issue
Block a user