From a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 16 Dec 2013 12:30:22 -0200 Subject: integer exponentiation with negative exponent is invalid --- lcode.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lcode.c') diff --git a/lcode.c b/lcode.c index 4dd823f2..34dadd1f 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.71 2013/06/25 18:57:18 roberto Exp roberto $ +** $Id: lcode.c,v 2.72 2013/08/30 16:01:37 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -754,12 +754,14 @@ static int constfolding (OpCode op, expdesc *e1, expdesc *e2) { TValue v1, v2, res; lua_Integer i; if (!tonumeral(e1, &v1) || !tonumeral(e2, &v2)) - return 0; + return 0; /* non-numeric operands */ if (op == OP_IDIV && (!tointeger(&v1, &i) || !tointeger(&v2, &i) || i == 0)) return 0; /* avoid division by 0 and conversion errors */ - if (op == OP_MOD && ttisinteger(&v1) && ttisinteger(&v2) && ivalue(&v2) == 0) - return 0; /* avoid module by 0 at compile time */ + if (ttisinteger(&v1) && ttisinteger(&v2) && /* for integer operations... */ + ((op == OP_MOD && ivalue(&v2) == 0) || /* ...avoid module by 0... */ + (op == OP_POW && ivalue(&v2) < 0))) /* ...and negative exponents */ + return 0; luaO_arith(NULL, op - OP_ADD + LUA_OPADD, &v1, &v2, &res); if (ttisinteger(&res)) { e1->k = VKINT; -- cgit v1.2.3-55-g6feb