aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-26 16:55:37 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-27 22:43:24 +1000
commit290704d7bd80907d7442f50b0bd56fdd2794107e (patch)
tree28c1139d5356a04ee2b0ce7ca0bd392e45c5748f
parent7807868d67aa6f24a22eff2a62964a1bafb05ac7 (diff)
downloadfengari-290704d7bd80907d7442f50b0bd56fdd2794107e.tar.gz
fengari-290704d7bd80907d7442f50b0bd56fdd2794107e.tar.bz2
fengari-290704d7bd80907d7442f50b0bd56fdd2794107e.zip
src/ldo.js: Make sure to extend stack before assigning in seterrorobj
-rw-r--r--src/ldo.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 84bf2b6..4c53f11 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -22,6 +22,12 @@ const CT = defs.constant_types;
const TS = defs.thread_status;
const seterrorobj = function(L, errcode, oldtop) {
+ let current_top = L.top;
+
+ /* extend stack so that L.stack[oldtop] is sure to exist */
+ while (L.top < oldtop + 1)
+ L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
+
switch (errcode) {
case TS.LUA_ERRMEM: {
lobject.setsvalue2s(L, oldtop, lstring.luaS_newliteral(L, "not enough memory"));
@@ -32,17 +38,12 @@ const seterrorobj = function(L, errcode, oldtop) {
break;
}
default: {
- lobject.setobjs2s(L, oldtop, L.top - 1);
+ lobject.setobjs2s(L, oldtop, current_top - 1);
}
}
- if (L.top < oldtop + 1) {
- while (L.top < oldtop + 1)
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TNIL, null);
- } else {
- while (L.top > oldtop + 1)
- delete L.stack[--L.top];
- }
+ while (L.top > oldtop + 1)
+ delete L.stack[--L.top];
};
const ERRORSTACKSIZE = luaconf.LUAI_MAXSTACK + 200;