Skip to content

Commit a585eae

Browse files
committed
Fixed bug: Negation overflow in getlocal/setlocal
1 parent d2c2e32 commit a585eae

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ldebug.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ static const char *upvalname (const Proto *p, int uv) {
188188
static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
189189
if (clLvalue(s2v(ci->func))->p->is_vararg) {
190190
int nextra = ci->u.l.nextraargs;
191-
if (n <= nextra) {
192-
*pos = ci->func - nextra + (n - 1);
191+
if (n >= -nextra) { /* 'n' is negative */
192+
*pos = ci->func - nextra - (n + 1);
193193
return "(vararg)"; /* generic name for any vararg */
194194
}
195195
}
@@ -202,7 +202,7 @@ const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {
202202
const char *name = NULL;
203203
if (isLua(ci)) {
204204
if (n < 0) /* access to vararg values? */
205-
return findvararg(ci, -n, pos);
205+
return findvararg(ci, n, pos);
206206
else
207207
name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
208208
}

0 commit comments

Comments
 (0)