aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-17 17:20:00 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-17 17:20:00 -0200
commit49dae52d0808776f5861eb33efa1d13b05e44512 (patch)
tree6f2f5578539ff00b6957522e3909293ce6de58ee /ltm.c
parent104d249ffbf76828caa5e204979f5ddad45f2bcb (diff)
downloadlua-49dae52d0808776f5861eb33efa1d13b05e44512.tar.gz
lua-49dae52d0808776f5861eb33efa1d13b05e44512.tar.bz2
lua-49dae52d0808776f5861eb33efa1d13b05e44512.zip
correct way to check stack space for vararg functions
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ltm.c b/ltm.c
index be7dc4f0..e46cc150 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.60 2018/02/09 15:16:06 roberto Exp roberto $ 2** $Id: ltm.c,v 2.61 2018/02/15 15:34:29 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -216,12 +216,13 @@ int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
216} 216}
217 217
218 218
219void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci) { 219void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci,
220 Proto *p) {
220 int i; 221 int i;
221 int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ 222 int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */
222 int nextra = actual - nfixparams; /* number of extra arguments */ 223 int nextra = actual - nfixparams; /* number of extra arguments */
223 ci->u.l.nextraargs = nextra; 224 ci->u.l.nextraargs = nextra;
224 checkstackGC(L, nfixparams + 1); 225 checkstackGC(L, p->maxstacksize + 1);
225 /* copy function to the top of the stack */ 226 /* copy function to the top of the stack */
226 setobjs2s(L, L->top++, ci->func); 227 setobjs2s(L, L->top++, ci->func);
227 /* move fixed parameters to the top of the stack */ 228 /* move fixed parameters to the top of the stack */
@@ -231,6 +232,7 @@ void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci) {
231 } 232 }
232 ci->func += actual + 1; 233 ci->func += actual + 1;
233 ci->top += actual + 1; 234 ci->top += actual + 1;
235 lua_assert(L->top <= ci->top && ci->top <= L->stack_last);
234} 236}
235 237
236 238