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.
Unified · Split
| @@ -6783,13 +6783,14 @@ static int decl_designator(CType *type, Section *sec, unsigned long c, · 6782 unmodified lines | ||
| 6783 | 6783 | c += index * elem_size; |
| 6784 | 6784 | nb_elems = index_last - index + 1; |
| 6785 | 6785 | } else { |
| 6786 | − int cumofs = 0; | |
| 6786 | + int cumofs; | |
| 6787 | 6787 | next(); |
| 6788 | 6788 | l = tok; |
| 6789 | 6789 | struct_field: |
| 6790 | 6790 | next(); |
| 6791 | 6791 | if ((type->t & VT_BTYPE) != VT_STRUCT) |
| 6792 | 6792 | expect("struct/union type"); |
| 6793 | + cumofs = 0; | |
| 6793 | 6794 | f = find_field(type, l, &cumofs); |
| 6794 | 6795 | if (!f) |
| 6795 | 6796 | expect("field"); |
| @@ -175,6 +175,12 @@ void foo (struct W *w, struct pkthdr *phdr_) · 174 unmodified lines | ||
| 175 | 175 | struct T lt2 = { { [1 ... 5] = 9, [6 ... 10] = elt, [4 ... 7] = elt+1 }, 1 }; |
| 176 | 176 | struct SSU lssu1 = { 5, 3 }; |
| 177 | 177 | struct SSU lssu2 = { .y = 5, .x = 3 }; |
| 178 | + /* designated initializers in GNU form */ | |
| 179 | +#if defined(__GNUC__) || defined(__TINYC__) | |
| 180 | + struct S ls4 = {a: 1, b: 2, c: {3, 4}}; | |
| 181 | +#else | |
| 182 | + struct S ls4 = {.a = 1, .b = 2, .c = {3, 4}}; | |
| 183 | +#endif | |
| 178 | 184 | print(ls); |
| 179 | 185 | print(ls2); |
| 180 | 186 | print(lt); |
| @@ -194,6 +200,7 @@ void foo (struct W *w, struct pkthdr *phdr_) · 13 unmodified lines | ||
| 194 | 200 | print(lssu1); |
| 195 | 201 | print(lssu2); |
| 196 | 202 | print(flow); |
| 203 | + print(ls4); | |
| 197 | 204 | } |
| 198 | 205 | #endif |
| 199 | 206 | |
| @@ -39,6 +39,7 @@ lt2: 0 9 9 9 43 43 43 43 42 42 42 0 0 0 0 0 1 · 38 unmodified lines | ||
| 39 | 39 | lssu1: 5 0 0 0 3 0 0 0 |
| 40 | 40 | lssu2: 5 0 0 0 3 0 0 0 |
| 41 | 41 | 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 |
| 42 | +ls4: 1 2 3 4 | |
| 42 | 43 | one |
| 43 | 44 | two |
| 44 | 45 | three |