From: Wolfgang Bumiller Date: Sat, 31 Aug 2013 09:35:12 +0000 (+0200) Subject: Don't allow a stale 'some_type;' declaration without an actual variable name; Same... X-Git-Tag: 0.3.5~108 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=702a7664ded1b1b38e9d6895e0d510c8cd0c3b4d;p=xonotic%2Fgmqcc.git Don't allow a stale 'some_type;' declaration without an actual variable name; Same for typedef; closes #119 --- diff --git a/parser.c b/parser.c index cbca105..ea9e000 100644 --- a/parser.c +++ b/parser.c @@ -4658,6 +4658,11 @@ static ast_value *parse_arraysize(parser_t *parser, ast_value *var) * The base type makes up every bit of type information which comes *before* the * variable name. * + * NOTE: The value must either be named, have a NULL name, or a name starting + * with '<'. In the first case, this will be the actual variable or type + * name, in the other cases it is assumed that the name will appear + * later, and an error is generated otherwise. + * * The following will be parsed in its entirety: * void() foo() * The 'basetype' in this case is 'void()' @@ -4818,6 +4823,13 @@ static bool parse_typedef(parser_t *parser) if (!typevar) return false; + /* while parsing types, the ast_value's get named '' */ + if (!typevar->name || typevar->name[0] == '<') { + parseerror(parser, "missing name in typedef"); + ast_delete(typevar); + return false; + } + if ( (old = parser_find_var(parser, typevar->name)) ) { parseerror(parser, "cannot define a type with the same name as a variable: %s\n" " -> `%s` has been declared here: %s:%i", @@ -4983,6 +4995,14 @@ static bool parse_variable(parser_t *parser, ast_block *localblock, bool nofield return false; } + /* while parsing types, the ast_value's get named '' */ + if (!var->name || var->name[0] == '<') { + parseerror(parser, "declaration does not declare anything"); + if (basetype) + ast_delete(basetype); + return false; + } + while (true) { proto = NULL; wasarray = false;