aboutsummaryrefslogtreecommitdiff
path: root/testes/errors.lua
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2025-10-10 13:22:19 -0300
committerRoberto I <roberto@inf.puc-rio.br>2025-10-10 13:22:19 -0300
commit3347c9d32d4d91b6139bff475c78cf0c4796e2a7 (patch)
tree008f1f82a5481149ce07328a188b72b535409f84 /testes/errors.lua
parent25c54fe60e22d05cdfaa48c64372d354efa59547 (diff)
downloadlua-3347c9d32d4d91b6139bff475c78cf0c4796e2a7.tar.gz
lua-3347c9d32d4d91b6139bff475c78cf0c4796e2a7.tar.bz2
lua-3347c9d32d4d91b6139bff475c78cf0c4796e2a7.zip
Initialization of too many locals break assertion
The check for limit of local variables is made after generating code to initialize them. If there are too many local variables not initialized, the coding of instruction OP_LOADNIL could overflow an argument.
Diffstat (limited to 'testes/errors.lua')
-rw-r--r--testes/errors.lua19
1 files changed, 12 insertions, 7 deletions
diff --git a/testes/errors.lua b/testes/errors.lua
index 4230a352..00a43fc6 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -689,21 +689,26 @@ end
689-- testing syntax limits 689-- testing syntax limits
690 690
691local function testrep (init, rep, close, repc, finalresult) 691local function testrep (init, rep, close, repc, finalresult)
692 local s = init .. string.rep(rep, 100) .. close .. string.rep(repc, 100) 692 local function gencode (n)
693 local res, msg = load(s) 693 return init .. string.rep(rep, n) .. close .. string.rep(repc, n)
694 assert(res) -- 100 levels is OK 694 end
695 local res, msg = load(gencode(100)) -- 100 levels is OK
696 assert(res)
695 if (finalresult) then 697 if (finalresult) then
696 assert(res() == finalresult) 698 assert(res() == finalresult)
697 end 699 end
698 s = init .. string.rep(rep, 500) 700 local res, msg = load(gencode(500)) -- 500 levels not ok
699 local res, msg = load(s) -- 500 levels not ok
700 assert(not res and (string.find(msg, "too many") or 701 assert(not res and (string.find(msg, "too many") or
701 string.find(msg, "overflow"))) 702 string.find(msg, "overflow")))
702end 703end
703 704
705testrep("local a", ",a", ";", "") -- local variables
706testrep("local a", ",a", "= 1", ",1") -- local variables initialized
707testrep("local a", ",a", "= f()", "") -- local variables initialized
704testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment 708testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment
705testrep("local a; a=", "{", "0", "}") 709testrep("local a; a=", "{", "0", "}") -- constructors
706testrep("return ", "(", "2", ")", 2) 710testrep("return ", "(", "2", ")", 2) -- parentheses
711-- nested calls (a(a(a(a(...)))))
707testrep("local function a (x) return x end; return ", "a(", "2.2", ")", 2.2) 712testrep("local function a (x) return x end; return ", "a(", "2.2", ")", 2.2)
708testrep("", "do ", "", " end") 713testrep("", "do ", "", " end")
709testrep("", "while a do ", "", " end") 714testrep("", "while a do ", "", " end")