aboutsummaryrefslogtreecommitdiff
path: root/lobject.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 /lobject.c
parent1a19893d6f8ee16944168a3f2c99002f70522f4c (diff)
downloadlua-a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434.tar.gz
lua-a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434.tar.bz2
lua-a8f8c7fd80a5c7e630fd4bf7f858d05024f6b434.zip
integer exponentiation with negative exponent is invalid
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/lobject.c b/lobject.c
index 92721332..32f4a191 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.67 2013/06/25 18:58:32 roberto Exp roberto $ 2** $Id: lobject.c,v 2.68 2013/07/10 17:15:12 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -77,7 +77,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
77 case LUA_OPSUB:return intop(-, v1, v2); 77 case LUA_OPSUB:return intop(-, v1, v2);
78 case LUA_OPMUL:return intop(*, v1, v2); 78 case LUA_OPMUL:return intop(*, v1, v2);
79 case LUA_OPMOD: return luaV_mod(L, v1, v2); 79 case LUA_OPMOD: return luaV_mod(L, v1, v2);
80 case LUA_OPPOW: return luaV_pow(v1, v2); 80 case LUA_OPPOW: return luaV_pow(L, v1, v2);
81 case LUA_OPUNM: return intop(-, 0, v1); 81 case LUA_OPUNM: return intop(-, 0, v1);
82 default: lua_assert(0); return 0; 82 default: lua_assert(0); return 0;
83 } 83 }
@@ -110,8 +110,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
110 } 110 }
111 else { /* other operations */ 111 else { /* other operations */
112 lua_Number n1; lua_Number n2; 112 lua_Number n1; lua_Number n2;
113 if (ttisinteger(p1) && ttisinteger(p2) && op != LUA_OPDIV && 113 if (ttisinteger(p1) && ttisinteger(p2) && op != LUA_OPDIV) {
114 (op != LUA_OPPOW || ivalue(p2) >= 0)) {
115 setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2))); 114 setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));
116 return; 115 return;
117 } 116 }
@@ -122,7 +121,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
122 /* else go to the end */ 121 /* else go to the end */
123 } 122 }
124 /* could not perform raw operation; try metmethod */ 123 /* could not perform raw operation; try metmethod */
125 lua_assert(L != NULL); /* cannot fail when folding (compile time) */ 124 lua_assert(L != NULL); /* should not fail when folding (compile time) */
126 luaT_trybinTM(L, p1, p2, res, cast(TMS, op - LUA_OPADD + TM_ADD)); 125 luaT_trybinTM(L, p1, p2, res, cast(TMS, op - LUA_OPADD + TM_ADD));
127} 126}
128 127