diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-26 16:55:37 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-27 22:43:24 +1000 |
commit | 290704d7bd80907d7442f50b0bd56fdd2794107e (patch) | |
tree | 28c1139d5356a04ee2b0ce7ca0bd392e45c5748f /src/ldo.js | |
parent | 7807868d67aa6f24a22eff2a62964a1bafb05ac7 (diff) | |
download | fengari-290704d7bd80907d7442f50b0bd56fdd2794107e.tar.gz fengari-290704d7bd80907d7442f50b0bd56fdd2794107e.tar.bz2 fengari-290704d7bd80907d7442f50b0bd56fdd2794107e.zip |
src/ldo.js: Make sure to extend stack before assigning in seterrorobj
Diffstat (limited to 'src/ldo.js')
-rw-r--r-- | src/ldo.js | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -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; |