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
4591 parse_attribute(ad);4591 parse_attribute(ad);
4592 post = type_decl(type, ad, v, td);4592 post = type_decl(type, ad, v, td);
4593 skip(')');4593 skip(')');
4594 }4594 } else
4595 goto abstract;
4595 } else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {4596 } else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
4596 /* type identifier */4597 /* type identifier */
4597 *v = tok;4598 *v = tok;
4598 next();4599 next();
4599 } else {4600 } else {
4601 abstract:
4600 if (!(td & TYPE_ABSTRACT))4602 if (!(td & TYPE_ABSTRACT))
4601 expect("identifier");4603 expect("identifier");
4602 *v = 0;4604 *v = 0;
tests/tests2/60_errors_and_warnings.c+11−0
@@ -130,4 +130,15 @@ static enum myenum { L = -1 } L; · 129 unmodified lines
130void foo(void) {130void foo(void) {
131static enum myenum { L = -1 } L; 131static enum myenum { L = -1 } L;
132}132}
133#elif defined test_abstract_decls
134int bar(const char *()); // abstract declarator here is okay
135int bar (const char *(*g)()) // should match this 'g' argument
136{
137 g();
138 return 42;
139}
140int foo(int ()) // abstract decl is wrong in definitions
141{
142 return 0;
143}
133#endif144#endif
tests/tests2/60_errors_and_warnings.expect+3−0
@@ -59,3 +59,6 @@ · 58 unmodified lines
59 59
60[test_duplicate_def_2]60[test_duplicate_def_2]
6160_errors_and_warnings.c:131: error: redeclaration of 'L'6160_errors_and_warnings.c:131: error: redeclaration of 'L'
62
63[test_abstract_decls]
6460_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