aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-12-16 12:30:22 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-12-16 12:30:22 -0200
commita8f8c7fd80a5c7e630fd4bf7f858d05024f6b434 (patch)
treeb5193ced2c4516a8fe4c6a5af05e0d7d5c27d49c /lcode.c
parent1a19893d6f8ee16944168a3f2c99002f70522f4c (diff)
downloadlua-a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434.tar.gz
lua-a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434.tar.bz2
lua-a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434.zip
integer exponentiation with negative exponent is invalid
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lcode.c b/lcode.c
index 4dd823f2..34dadd1f 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.71 2013/06/25 18:57:18 roberto Exp roberto $ 2** $Id: lcode.c,v 2.72 2013/08/30 16:01:37 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*/
@@ -754,12 +754,14 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) {
754 TValue v1, v2, res; 754 TValue v1, v2, res;
755 lua_Integer i; 755 lua_Integer i;
756 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2)) 756 if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2))
757 return 0; 757 return 0; /* non-numeric operands */
758 if (op == OP_IDIV && 758 if (op == OP_IDIV &&
759 (!tointeger(&v1, &i) || !tointeger(&v2, &i) || i == 0)) 759 (!tointeger(&v1, &i) || !tointeger(&v2, &i) || i == 0))
760 return 0; /* avoid division by 0 and conversion errors */ 760 return 0; /* avoid division by 0 and conversion errors */
761 if (op == OP_MOD && ttisinteger(&v1) && ttisinteger(&v2) && ivalue(&v2) == 0) 761 if (ttisinteger(&v1) && ttisinteger(&v2) && /* for integer operations... */
762 return 0; /* avoid module by 0 at compile time */ 762 ((op == OP_MOD && ivalue(&v2) == 0) || /* ...avoid module by 0... */
763 (op == OP_POW && ivalue(&v2) < 0))) /* ...and negative exponents */
764 return 0;
763 luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res); 765 luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res);
764 if (ttisinteger(&res)) { 766 if (ttisinteger(&res)) {
765 e1->k = VKINT; 767 e1->k = VKINT;