scc

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

commit 4b7c7bc9c581cd8305bd2b7f9741c25f6ec5943f
parent 3b828bbd092e2bcdc06371f6cdb915c1fa49a6ff
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 22 Apr 2014 17:10:40 +0200

Forbid modify a void expression

A void expression cannot be modified, so this check
must be explicitily done.

Diffstat:
Mexpr.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/expr.c b/expr.c @@ -331,6 +331,8 @@ incdec(Node *np, char op) if (!np->b.lvalue) goto nolvalue; + if (np->utype == voidtype) + goto voidassign; if (isconst(tp->op)) goto const_mod; @@ -344,6 +346,9 @@ incdec(Node *np, char op) goto bad_type; } +voidassign: + err = "invalid use of void expression"; + goto error; nolvalue: err = "lvalue required in operation"; goto error; @@ -720,11 +725,16 @@ assign(void) } if (!np->b.lvalue) goto nolvalue; + if (np->utype == voidtype) + goto voidassign; if (isconst(np->type->op)) goto const_mod; next(); np = (fun)(op, np, eval(assign())); } +voidassign: + err = "invalid use of void expression"; + goto error; const_mod: err = "const value modified"; goto error;