mirror of
https://github.com/mirror/tinycc.git
synced 2024-12-26 03:50:07 +08:00
Fix invalid size with GNU designated initializers
the uninitialized cumofs was leading to random sizes for the memset when initializing local structures, potentially leading to segfaults from it. Only a problem with GNU designated initializers, which we didn't test very well. See testcase.
This commit is contained in:
parent
ce1ef5b8fc
commit
9e429dbef0
3
tccgen.c
3
tccgen.c
@ -6783,13 +6783,14 @@ static int decl_designator(CType *type, Section *sec, unsigned long c,
|
||||
c += index * elem_size;
|
||||
nb_elems = index_last - index + 1;
|
||||
} else {
|
||||
int cumofs = 0;
|
||||
int cumofs;
|
||||
next();
|
||||
l = tok;
|
||||
struct_field:
|
||||
next();
|
||||
if ((type->t & VT_BTYPE) != VT_STRUCT)
|
||||
expect("struct/union type");
|
||||
cumofs = 0;
|
||||
f = find_field(type, l, &cumofs);
|
||||
if (!f)
|
||||
expect("field");
|
||||
|
@ -175,6 +175,12 @@ void foo (struct W *w, struct pkthdr *phdr_)
|
||||
struct T lt2 = { { [1 ... 5] = 9, [6 ... 10] = elt, [4 ... 7] = elt+1 }, 1 };
|
||||
struct SSU lssu1 = { 5, 3 };
|
||||
struct SSU lssu2 = { .y = 5, .x = 3 };
|
||||
/* designated initializers in GNU form */
|
||||
#if defined(__GNUC__) || defined(__TINYC__)
|
||||
struct S ls4 = {a: 1, b: 2, c: {3, 4}};
|
||||
#else
|
||||
struct S ls4 = {.a = 1, .b = 2, .c = {3, 4}};
|
||||
#endif
|
||||
print(ls);
|
||||
print(ls2);
|
||||
print(lt);
|
||||
@ -194,6 +200,7 @@ void foo (struct W *w, struct pkthdr *phdr_)
|
||||
print(lssu1);
|
||||
print(lssu2);
|
||||
print(flow);
|
||||
print(ls4);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -39,6 +39,7 @@ lt2: 0 9 9 9 43 43 43 43 42 42 42 0 0 0 0 0 1
|
||||
lssu1: 5 0 0 0 3 0 0 0
|
||||
lssu2: 5 0 0 0 3 0 0 0
|
||||
flow: 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
ls4: 1 2 3 4
|
||||
one
|
||||
two
|
||||
three
|
||||
|
Loading…
Reference in New Issue
Block a user