From fc06de96b0458e9b2fd8442523891fccbd7bf3d1 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 15:55:47 +1000 Subject: src/lmathlib.js: Math.abs can return out of range integers --- src/lmathlib.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/lmathlib.js') 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; -- cgit v1.2.3-54-g00ecf