Skip to content

Commit 3e88b72

Browse files
committed
A return can have at most 254 values
1 parent 8b752dd commit 3e88b72

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lcode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ void luaK_ret (FuncState *fs, int first, int nret) {
208208
case 1: op = OP_RETURN1; break;
209209
default: op = OP_RETURN; break;
210210
}
211+
if (nret + 1 > MAXARG_B)
212+
luaX_syntaxerror(fs->ls, "too many returns");
211213
luaK_codeABC(fs, op, first, nret + 1, 0);
212214
}
213215

testes/calls.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,5 +518,16 @@ do -- check reuse of strings in dumps
518518
end
519519
end
520520

521+
522+
do -- test limit of multiple returns (254 values)
523+
local code = "return 10" .. string.rep(",10", 253)
524+
local res = {assert(load(code))()}
525+
assert(#res == 254 and res[254] == 10)
526+
527+
code = code .. ",10"
528+
local status, msg = load(code)
529+
assert(not status and string.find(msg, "too many returns"))
530+
end
531+
521532
print('OK')
522533
return deep

0 commit comments

Comments
 (0)