[hackers] [scc] Allow only integer expressions in switch || Roberto E. Vargas Caballero
commit 0c5e2751bdf1b8db6700733e84b2887f7f38aabc
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Jul 24 14:03:59 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Jul 24 14:03:59 2015 +0200
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.
diff --git a/cc1/stmt.c b/cc1/stmt.c
index 072686e..e4b1cd9 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -219,8 +219,9 @@ Switch(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
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);
Received on Fri Jul 24 2015 - 17:39:08 CEST
This archive was generated by hypermail 2.3.0
: Fri Jul 24 2015 - 17:48:13 CEST