summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-04 11:54:16 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-04 11:55:49 +1000
commit24e4656be7105e090e2f1a76a294daf2d9c293af (patch)
tree92d92591e70766bfd962e5e8f95300fad59a024c /src
parentadb15f3073139981fa38ed61587513a92065cf03 (diff)
downloadfengari-24e4656be7105e090e2f1a76a294daf2d9c293af.tar.gz
fengari-24e4656be7105e090e2f1a76a294daf2d9c293af.tar.bz2
fengari-24e4656be7105e090e2f1a76a294daf2d9c293af.zip
Add more/correct validation around integers
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js7
-rw-r--r--src/llimit.js4
-rw-r--r--src/lmathlib.js2
-rw-r--r--src/ltable.js4
4 files changed, 9 insertions, 8 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 6ef5a9e..909822f 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -205,9 +205,9 @@ const lua_pushnumber = function(L, n) {
};
const lua_pushinteger = function(L, n) {
- assert(typeof n === "number");
+ assert(typeof n === "number" && (n|0) === n);
- L.stack[L.top++] = new TValue(CT.LUA_TNUMINT, n|0);
+ L.stack[L.top++] = new TValue(CT.LUA_TNUMINT, n);
assert(L.top <= L.ci.top, "stack overflow");
};
@@ -374,7 +374,7 @@ const lua_setfield = function(L, idx, k) {
};
const lua_seti = function(L, idx, n) {
- assert(typeof n === "number");
+ assert(typeof n === "number" && (n|0) === n);
assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack");
let t = index2addr(L, idx);
L.stack[L.top++] = new TValue(CT.LUA_TNUMINT, n);
@@ -587,6 +587,7 @@ const lua_getfield = function(L, idx, k) {
};
const lua_geti = function(L, idx, n) {
+ assert(typeof n === "number" && (n|0) === n);
let t = index2addr(L, idx);
L.stack[L.top++] = new TValue(CT.LUA_TNUMINT, n);
assert(L.top <= L.ci.top, "stack overflow");
diff --git a/src/llimit.js b/src/llimit.js
index 06b8370..c8455b8 100644
--- a/src/llimit.js
+++ b/src/llimit.js
@@ -5,11 +5,11 @@ const LUAI_MAXCCALLS = 200;
module.exports.LUAI_MAXCCALLS = LUAI_MAXCCALLS;
const LUA_MAXINTEGER = 2147483647;
module.exports.LUA_MAXINTEGER = LUA_MAXINTEGER;
-const LUA_MININTEGER = -2147483647;
+const LUA_MININTEGER = -2147483648;
module.exports.LUA_MININTEGER = LUA_MININTEGER;
// If later integers are more than 32bit, LUA_MAXINTEGER will then be != MAX_INT
const MAX_INT = 2147483647;
module.exports.MAX_INT = MAX_INT;
-const MIN_INT = -2147483647;
+const MIN_INT = -2147483648;
module.exports.MIN_INT = MIN_INT;
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 7d3a082..8c7b8a5 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -39,7 +39,7 @@ const math_random = function(L) {
lua.to_luastring("interval too large", true));
r *= (up - low) + 1;
- lua.lua_pushinteger(L, r + low);
+ lua.lua_pushinteger(L, Math.floor(r) + low);
return 1;
};
diff --git a/src/ltable.js b/src/ltable.js
index d6fffe9..ac12bd2 100644
--- a/src/ltable.js
+++ b/src/ltable.js
@@ -49,7 +49,7 @@ const getgeneric = function(t, hash) {
};
const luaH_getint = function(t, key) {
- assert(typeof key == "number");
+ assert(typeof key == "number" && (key|0) === key);
return getgeneric(t, key);
};
@@ -79,7 +79,7 @@ const setgeneric = function(t, hash, key) {
};
const luaH_setint = function(t, key, value) {
- assert(typeof key == "number" && value instanceof lobject.TValue && (key|0) === key);
+ assert(typeof key == "number" && (key|0) === key && value instanceof lobject.TValue);
let hash = key; /* table_hash known result */
let v = t.strong.get(hash);
if (v) {