From 3347c9d32d4d91b6139bff475c78cf0c4796e2a7 Mon Sep 17 00:00:00 2001 From: Roberto I Date: Fri, 10 Oct 2025 13:22:19 -0300 Subject: 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. --- testes/errors.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'testes') 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 -- testing syntax limits local function testrep (init, rep, close, repc, finalresult) - local s = init .. string.rep(rep, 100) .. close .. string.rep(repc, 100) - local res, msg = load(s) - assert(res) -- 100 levels is OK + local function gencode (n) + return init .. string.rep(rep, n) .. close .. string.rep(repc, n) + end + local res, msg = load(gencode(100)) -- 100 levels is OK + assert(res) if (finalresult) then assert(res() == finalresult) end - s = init .. string.rep(rep, 500) - local res, msg = load(s) -- 500 levels not ok + local res, msg = load(gencode(500)) -- 500 levels not ok assert(not res and (string.find(msg, "too many") or string.find(msg, "overflow"))) end +testrep("local a", ",a", ";", "") -- local variables +testrep("local a", ",a", "= 1", ",1") -- local variables initialized +testrep("local a", ",a", "= f()", "") -- local variables initialized testrep("local a; a", ",a", "= 1", ",1") -- multiple assignment -testrep("local a; a=", "{", "0", "}") -testrep("return ", "(", "2", ")", 2) +testrep("local a; a=", "{", "0", "}") -- constructors +testrep("return ", "(", "2", ")", 2) -- parentheses +-- nested calls (a(a(a(a(...))))) testrep("local function a (x) return x end; return ", "a(", "2.2", ")", 2.2) testrep("", "do ", "", " end") testrep("", "while a do ", "", " end") -- cgit v1.2.3-55-g6feb