From 290704d7bd80907d7442f50b0bd56fdd2794107e Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 26 May 2017 16:55:37 +1000 Subject: src/ldo.js: Make sure to extend stack before assigning in seterrorobj --- src/ldo.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') 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; -- cgit v1.2.3-70-g09d2