scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0e120abe46b29d6c3f3d00d6fda467a3f8949d37
parent a9f59c62a1ef80c97cbf32e3aa11410f7ef9f455
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 27 Aug 2015 15:59:24 +0200

Fix check of invalid field in expressions

It is impossible to have yylval.sym == NULL when yytoken == IDEN,
but the symbol not have the ISDECLARED flag.

Diffstat:
Mcc1/expr.c | 21++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -681,23 +681,26 @@ field(Node *np) { Symbol *sym; + namespace = np->type->ns; + next(); + namespace = NS_IDEN; + + sym = yylval.sym; + if (yytoken != IDEN) + unexpected(); + next(); + switch (BTYPE(np)) { case STRUCT: case UNION: - namespace = np->type->ns; - next(); - namespace = NS_IDEN; - - if (yytoken != IDEN) - unexpected(); - if ((sym = yylval.sym) == NULL) + if ((sym->flags & ISDECLARED) == 0) error("incorrect field in struct/union"); - next(); np = node(OFIELD, sym->type, np, varnode(sym)); np->lvalue = 1; return np; default: - error("struct or union expected"); + error("request for member '%s' in something not a structure or union", + yylval.sym->name); } }