From c5363a1b58573162ef13ba4a345bd48ad3c355d9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 2 Nov 2015 12:06:01 -0200 Subject: in 'luaD_precall', in vararg functions, complete missing parameters only after moving them to final place (avoids checking the stack again) --- lvm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index 051b948c..27ade135 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.257 2015/10/28 14:50:09 roberto Exp roberto $ +** $Id: lvm.c,v 2.258 2015/11/02 11:43:17 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -1274,23 +1274,21 @@ void luaV_execute (lua_State *L) { vmbreak; } vmcase(OP_VARARG) { - int b = GETARG_B(i) - 1; + int b = GETARG_B(i) - 1; /* required results */ int j; int n = cast_int(base - ci->func) - cl->p->numparams - 1; + if (n < 0) /* less arguments than parameters? */ + n = 0; /* no vararg arguments */ if (b < 0) { /* B == 0? */ b = n; /* get all var. arguments */ Protect(luaD_checkstack(L, n)); ra = RA(i); /* previous call may change the stack */ L->top = ra + n; } - for (j = 0; j < b; j++) { - if (j < n) { - setobjs2s(L, ra + j, base - n + j); - } - else { - setnilvalue(ra + j); - } - } + for (j = 0; j < b && j < n; j++) + setobjs2s(L, ra + j, base - n + j); + for (; j < b; j++) /* complete required results with nil */ + setnilvalue(ra + j); vmbreak; } vmcase(OP_EXTRAARG) { -- cgit v1.2.3-55-g6feb