shithub: scc

Download patch

ref: ad6ddff27bb2d95a73341bfa53ca5e3ed070162b
parent: 79f87ebac2588c8a6cc9e4304f61b1259a7355eb
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 15 10:43:19 EDT 2014

Check against zero in ternary code

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

--- a/expr.c
+++ b/expr.c
@@ -637,9 +637,10 @@
 	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;
 }