diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-08-19 18:39:25 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-08-19 18:39:25 -0300 |
commit | 3e88b72b8e71c0946d089a04876e7bdc61d187a9 (patch) | |
tree | 46e84129fc3d40c1fb66b6913ee3b70d0c1703b0 | |
parent | 8b752ddf14c1987411906d07a8c68f72f168b9b7 (diff) | |
download | lua-3e88b72b8e71c0946d089a04876e7bdc61d187a9.tar.gz lua-3e88b72b8e71c0946d089a04876e7bdc61d187a9.tar.bz2 lua-3e88b72b8e71c0946d089a04876e7bdc61d187a9.zip |
A return can have at most 254 values
-rw-r--r-- | lcode.c | 2 | ||||
-rw-r--r-- | testes/calls.lua | 11 |
2 files changed, 13 insertions, 0 deletions
@@ -208,6 +208,8 @@ void luaK_ret (FuncState *fs, int first, int nret) { | |||
208 | case 1: op = OP_RETURN1; break; | 208 | case 1: op = OP_RETURN1; break; |
209 | default: op = OP_RETURN; break; | 209 | default: op = OP_RETURN; break; |
210 | } | 210 | } |
211 | if (nret + 1 > MAXARG_B) | ||
212 | luaX_syntaxerror(fs->ls, "too many returns"); | ||
211 | luaK_codeABC(fs, op, first, nret + 1, 0); | 213 | luaK_codeABC(fs, op, first, nret + 1, 0); |
212 | } | 214 | } |
213 | 215 | ||
diff --git a/testes/calls.lua b/testes/calls.lua index 9a5eed0b..409a275d 100644 --- a/testes/calls.lua +++ b/testes/calls.lua | |||
@@ -518,5 +518,16 @@ do -- check reuse of strings in dumps | |||
518 | end | 518 | end |
519 | end | 519 | end |
520 | 520 | ||
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 | |||
521 | print('OK') | 532 | print('OK') |
522 | return deep | 533 | return deep |