History

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

grischka committed 13 years ago

Commit 69c2e7f1 parent 8c033a11 file · +8 −6Browse files

Unified · Split

tccgen.c+8−6
@@ -2764,6 +2764,7 @@ static void struct_decl(CType *type, int u) · 2763 unmodified lines
27642764 v = anon_sym++;
27652765 }
27662766 type1.t = a;
2767+ type1.ref = NULL;
27672768 /* we put an undefined size for struct/union */
27682769 s = sym_push(v | SYM_STRUCT, &type1, 0, -1);
27692770 s->r = 0; /* default alignment is zero as gcc */
@@ -5337,12 +5338,13 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 2567 unmodified lines
53375338
53385339 flexible_array = NULL;
53395340 if ((type->t & VT_BTYPE) == VT_STRUCT) {
5340− Sym *field;
5341− field = type->ref;
5342− while (field && field->next)
5343− field = field->next;
5344− if (field->type.t & VT_ARRAY && field->type.ref->c < 0)
5345− flexible_array = field;
5341+ Sym *field = type->ref->next;
5342+ if (field) {
5343+ while (field->next)
5344+ field = field->next;
5345+ if (field->type.t & VT_ARRAY && field->type.ref->c < 0)
5346+ flexible_array = field;
5347+ }
53465348 }
53475349
53485350 size = type_size(type, &align);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t