From 49dae52d0808776f5861eb33efa1d13b05e44512 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Sat, 17 Feb 2018 17:20:00 -0200 Subject: correct way to check stack space for vararg functions --- ltm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ltm.c') diff --git a/ltm.c b/ltm.c index be7dc4f0..e46cc150 100644 --- a/ltm.c +++ b/ltm.c @@ -1,5 +1,5 @@ /* -** $Id: ltm.c,v 2.60 2018/02/09 15:16:06 roberto Exp roberto $ +** $Id: ltm.c,v 2.61 2018/02/15 15:34:29 roberto Exp roberto $ ** Tag methods ** See Copyright Notice in lua.h */ @@ -216,12 +216,13 @@ int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, } -void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci) { +void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci, + Proto *p) { int i; int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ int nextra = actual - nfixparams; /* number of extra arguments */ ci->u.l.nextraargs = nextra; - checkstackGC(L, nfixparams + 1); + checkstackGC(L, p->maxstacksize + 1); /* copy function to the top of the stack */ setobjs2s(L, L->top++, ci->func); /* move fixed parameters to the top of the stack */ @@ -231,6 +232,7 @@ void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci) { } ci->func += actual + 1; ci->top += actual + 1; + lua_assert(L->top <= ci->top && ci->top <= L->stack_last); } -- cgit v1.2.3-55-g6feb