scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit ad6ddff27bb2d95a73341bfa53ca5e3ed070162b
parent 79f87ebac2588c8a6cc9e4304f61b1259a7355eb
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 15 Apr 2014 14:43:19 +0200

Check against zero in ternary code

All expressions must be evaluated before of taking
decisions based in then.

Diffstat:
expr.c | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/expr.c b/expr.c @@ -637,9 +637,10 @@ ternary(void) while (accept('?')) { ifyes = expr(); expect(':'); - ifno = expr(); + ifno = ternary(); /* TODO: check the types of ifno and ifyes */ - cond = ternarycode(cond, ifyes, ifno); + cond = ternarycode(compare(ONE, cond, constcode(zero)), + ifyes, ifno); } return cond; }