Skip to content

Commit 509ef25

Browse files
committed
tests/lapi: fix table_remove_test
Fix out-of-bound indices passed to `table.remove()`.
1 parent 51d08cf commit 509ef25

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/lapi/table_remove_test.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ local test_lib = require("lib")
1616

1717
local function TestOneInput(buf, _size)
1818
local fdp = luzer.FuzzedDataProvider(buf)
19-
local count = fdp:consume_integer(0, test_lib.MAX_INT)
19+
local count = fdp:consume_integer(1, test_lib.MAX_INT)
2020
local tbl = fdp:consume_strings(test_lib.MAX_STR_LEN, count)
2121

2222
local indices_count = fdp:consume_integer(0, #tbl)
23-
local indices = fdp:consume_integers(0, count, indices_count)
23+
local min_index = 0
24+
-- PUC Rio Lua 5.2+ raises an error "position out of bounds"
25+
-- when `pos` is equal to 0 and table is not empty.
26+
if test_lib.lua_current_version_ge_than(5, 2) then
27+
min_index = 1
28+
end
29+
local indices = fdp:consume_integers(min_index, count, indices_count)
2430
for _, idx in ipairs(indices) do
2531
local old_v = tbl[idx]
2632
assert(table.remove(tbl, idx) == old_v)

0 commit comments

Comments
 (0)