History

reject invalid arrays in post_type()

Pascal Cuoq committed 7 years ago

Commit cbbba011 parent 942b73b3 files · +39 −3Browse files

Unified · Split

3 files
  1. tccgen.c +8 −3
  2. tests/tests2/60_errors_and_warnings.c +16 −0
  3. tests/tests2/60_errors_and_warnings.expect +15 −0
tccgen.c+8−3
@@ -4377,7 +4377,7 @@ static int asm_label_instr(void) · 4376 unmodified lines
43774377
43784378 static int post_type(CType *type, AttributeDef *ad, int storage, int td)
43794379 {
4380− int n, l, t1, arg_size, align;
4380+ int n, l, t1, arg_size, align, unused_align;
43814381 Sym **plast, *s, *first;
43824382 AttributeDef ad1;
43834383 CType pt;
@@ -4503,10 +4503,15 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 119 unmodified lines
45034503 skip(']');
45044504 /* parse next post type */
45054505 post_type(type, ad, storage, 0);
4506− if (type->t == VT_FUNC)
4506+
4507+ if ((type->t & VT_BTYPE) == VT_FUNC)
45074508 tcc_error("declaration of an array of functions");
4509+ if ((type->t & VT_BTYPE) == VT_VOID
4510+ || type_size(type, &unused_align) < 0)
4511+ tcc_error("declaration of an array of incomplete type elements");
4512+
45084513 t1 |= type->t & VT_VLA;
4509−
4514+
45104515 if (t1 & VT_VLA) {
45114516 if (n < 0)
45124517 tcc_error("need explicit inner array size in VLAs");
tests/tests2/60_errors_and_warnings.c+16−0
@@ -182,4 +182,20 @@ void * _Alignas(16) p1; · 181 unmodified lines
182182 _Static_assert(ONE == 0, "don't show me this");
183183 _Static_assert(ONE == 1, "ONE is not 1");
184184
185+#elif defined test_void_array
186+ void t[3];
187+
188+#elif defined test_incomplete_enum_array
189+ enum e t[3];
190+
191+#elif defined test_incomplete_struct_array
192+ struct s t[3];
193+
194+#elif defined test_const_fun_array
195+ typedef void f(void);
196+ const f t[3];
197+
198+#elif defined test_incomplete_array_array
199+ int t[][3];
200+
185201 #endif
tests/tests2/60_errors_and_warnings.expect+15−0
@@ -86,3 +86,18 @@ · 85 unmodified lines
8686
8787 [test_static_assert]
8888 60_errors_and_warnings.c:183: error: "ONE is not 1"
89+
90+[test_void_array]
91+60_errors_and_warnings.c:186: error: declaration of an array of incomplete type elements
92+
93+[test_incomplete_enum_array]
94+60_errors_and_warnings.c:189: error: declaration of an array of incomplete type elements
95+
96+[test_incomplete_struct_array]
97+60_errors_and_warnings.c:192: error: declaration of an array of incomplete type elements
98+
99+[test_const_fun_array]
100+60_errors_and_warnings.c:196: error: declaration of an array of functions
101+
102+[test_incomplete_array_array]
103+60_errors_and_warnings.c:199: error: unknown type size

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