aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-22 15:55:47 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-22 15:55:47 +1000
commitfc06de96b0458e9b2fd8442523891fccbd7bf3d1 (patch)
tree4a790cd609fc134ba35c35a5cbc2b00cd57d9b5d /src
parent5da3fdc853268b197040ec63cc2dadc489358977 (diff)
downloadfengari-fc06de96b0458e9b2fd8442523891fccbd7bf3d1.tar.gz
fengari-fc06de96b0458e9b2fd8442523891fccbd7bf3d1.tar.bz2
fengari-fc06de96b0458e9b2fd8442523891fccbd7bf3d1.zip
src/lmathlib.js: Math.abs can return out of range integers
Diffstat (limited to 'src')
-rw-r--r--src/lmathlib.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 3e4486a..0c3b715 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -44,8 +44,11 @@ const math_random = function(L) {
};
const math_abs = function(L) {
- if (lua.lua_isinteger(L, 1))
- lua.lua_pushinteger(L, Math.abs(lua.lua_tointeger(L, 1)));
+ if (lua.lua_isinteger(L, 1)) {
+ let n = lua.lua_tointeger(L, 1);
+ if (n < 0) n = (-n)|0;
+ lua.lua_pushinteger(L, n);
+ }
else
lua.lua_pushnumber(L, Math.abs(lauxlib.luaL_checknumber(L, 1)));
return 1;