shithub: scc

Download patch

ref: 0c5e2751bdf1b8db6700733e84b2887f7f38aabc
parent: 4f3e4465ccb3e7c611c7996793abefe399787983
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jul 24 10:03:59 EDT 2015

Allow only integer expressions in switch

convert() can do some conversions that are not allowed in a switch,
like for example from a float to integer.

--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -219,8 +219,9 @@
 	expect(SWITCH);
 	expect ('(');
 	cond = expr();
-	if ((cond = convert(cond, inttype, 0)) == NULL)
+	if (cond->type->op != INT)
 		error("incorrect type in switch statement");
+	cond = convert(cond, inttype, 0);
 	expect (')');
 
 	lbreak = newsym(NS_LABEL);