aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lcode.c b/lcode.c
index ded49b0e..ffb263f7 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.67 2013/04/29 16:57:48 roberto Exp roberto $ 2** $Id: lcode.c,v 2.68 2013/05/02 12:37:24 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -741,11 +741,14 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
741 741
742static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { 742static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
743 TValue v1, v2, res; 743 TValue v1, v2, res;
744 lua_Integer i2; 744 lua_Integer i;
745 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2)) 745 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2))
746 return 0; 746 return 0;
747 if ((op == OP_IDIV || op == OP_MOD) && tointeger(&v2, &i2) && i2 == 0) 747 if (op == OP_IDIV &&
748 return 0; /* avoid division by 0 at compile time */ 748 (!tointeger(&v1, &i) || !tointeger(&v2, &i) || i == 0))
749 return 0; /* avoid division by 0 and conversion errors */
750 if (op == OP_MOD && ttisinteger(&v1) && ttisinteger(&v2) && ivalue(&v2) == 0)
751 return 0; /* avoid module by 0 at compile time */
749 luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res); 752 luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res);
750 if (ttisinteger(&res)) { 753 if (ttisinteger(&res)) {
751 e1->k = VKINT; 754 e1->k = VKINT;