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.
This commit is contained in:
Michael Matz 2019-03-12 17:27:15 +01:00
parent ef0397cf3d
commit 4b46e0ec63
3 changed files with 17 additions and 1 deletions

View File

@ -4591,12 +4591,14 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
parse_attribute(ad);
post = type_decl(type, ad, v, td);
skip(')');
}
} else
goto abstract;
} else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
/* type identifier */
*v = tok;
next();
} else {
abstract:
if (!(td & TYPE_ABSTRACT))
expect("identifier");
*v = 0;

View File

@ -130,4 +130,15 @@ static enum myenum { L = -1 } L;
void foo(void) {
static enum myenum { L = -1 } L;
}
#elif defined test_abstract_decls
int bar(const char *()); // abstract declarator here is okay
int bar (const char *(*g)()) // should match this 'g' argument
{
g();
return 42;
}
int foo(int ()) // abstract decl is wrong in definitions
{
return 0;
}
#endif

View File

@ -59,3 +59,6 @@
[test_duplicate_def_2]
60_errors_and_warnings.c:131: error: redeclaration of 'L'
[test_abstract_decls]
60_errors_and_warnings.c:141: error: identifier expected