From 91e09ea32148c34965809b8d69987d439d389870 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 18:06:40 +1000 Subject: Compare allowed stack indices to stack_last Not L.stack.length which is more equivalent to C's L->stacksize --- src/lapi.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/lapi.js') diff --git a/src/lapi.js b/src/lapi.js index 79c666c..ca5a8a0 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -94,7 +94,7 @@ const lua_checkstack = function(L, n) { let res; let ci = L.ci; assert(n >= 0, "negative 'n'"); - if (L.stack.length - L.top > n) /* stack large enough? */ + if (L.stack_last - L.top > n) /* stack large enough? */ res = true; else { /* no; need to grow stack */ let inuse = L.top + lstate.EXTRA_STACK; @@ -152,6 +152,7 @@ const lua_pushvalue = function(L, idx) { const lua_settop = function(L, idx) { let func = L.ci.funcOff; if (idx >= 0) { + assert(idx <= L.stack_last - (func + 1), "new top too large"); while (L.top < func + 1 + idx) L.stack[L.top++] = new TValue(CT.LUA_TNIL, null); L.top = func + 1 + idx; -- cgit v1.2.3-54-g00ecf