-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtable_foreach_test.lua
More file actions
39 lines (31 loc) · 1022 Bytes
/
table_foreach_test.lua
File metadata and controls
39 lines (31 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--[[
SPDX-License-Identifier: ISC
Copyright (c) 2023-2025, Sergey Bronnikov.
5.4 – Table Manipulation,
https://www.lua.org/manual/5.0/manual.html#5.4
Bad loop initialization in table.foreach(),
https://github.com/LuaJIT/LuaJIT/issues/844
string.dump(table.foreach) will trigger an assert,
https://github.com/LuaJIT/LuaJIT/issues/1038
Synopsis: table.foreach(table, f)
]]
local luzer = require("luzer")
local test_lib = require("lib")
-- Function `table.foreach` is deprecated in Lua 5.1.
if test_lib.lua_current_version_ge_than(5, 2) then
print("Unsupported version.")
os.exit(0)
end
local function TestOneInput(buf, _size)
local fdp = luzer.FuzzedDataProvider(buf)
local count = fdp:consume_integer(1, test_lib.MAX_INT)
local tbl = fdp:consume_strings(test_lib.MAX_STR_LEN, count)
local i = 0
local fn = function(_idx, _v) i = i + 1 end
table.foreach(tbl, fn)
assert(#tbl == i)
end
local args = {
artifact_prefix = "table_foreach_",
}
luzer.Fuzz(TestOneInput, nil, args)