History

Handle corner case for abstract decls

sometimes abstract decls in parameter lists left the returned name uninitialized potentially leading to segfaults, like in int f(int ()) { return 0; } Deal with this.

Michael Matz committed 7 years ago

Commit 4b46e0e1 parent ef0397c3 files · +17 −1Browse files

Unified · Split

3 files
  1. tccgen.c +3 −1
  2. tests/tests2/60_errors_and_warnings.c +11 −0
  3. tests/tests2/60_errors_and_warnings.expect +3 −0
tccgen.c+3−1
@@ -4591,12 +4591,14 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td) · 4590 unmodified lines
45914591 parse_attribute(ad);
45924592 post = type_decl(type, ad, v, td);
45934593 skip(')');
4594− }
4594+ } else
4595+ goto abstract;
45954596 } else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
45964597 /* type identifier */
45974598 *v = tok;
45984599 next();
45994600 } else {
4601+ abstract:
46004602 if (!(td & TYPE_ABSTRACT))
46014603 expect("identifier");
46024604 *v = 0;
tests/tests2/60_errors_and_warnings.c+11−0
@@ -130,4 +130,15 @@ static enum myenum { L = -1 } L; · 129 unmodified lines
130130 void foo(void) {
131131 static enum myenum { L = -1 } L;
132132 }
133+#elif defined test_abstract_decls
134+int bar(const char *()); // abstract declarator here is okay
135+int bar (const char *(*g)()) // should match this 'g' argument
136+{
137+ g();
138+ return 42;
139+}
140+int foo(int ()) // abstract decl is wrong in definitions
141+{
142+ return 0;
143+}
133144 #endif
tests/tests2/60_errors_and_warnings.expect+3−0
@@ -59,3 +59,6 @@ · 58 unmodified lines
5959
6060 [test_duplicate_def_2]
6161 60_errors_and_warnings.c:131: error: redeclaration of 'L'
62+
63+[test_abstract_decls]
64+60_errors_and_warnings.c:141: error: identifier expected

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