Skip to content

Commit 11fddde

Browse files
committed
xxx
1 parent 7fa3225 commit 11fddde

16 files changed

+39
-41
lines changed

tests/lapi/lib.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ local MIN_INT64 = math.mininteger or -0x8000000000000000
3838
local MAX_INT = 0x7fffffff
3939
local MIN_INT = -0x80000000
4040

41+
local MAX_STR_LEN = 4096
42+
4143
local function bitwise_op(op_name)
4244
return function(...)
4345
local n = select("#", ...)
@@ -87,6 +89,7 @@ return {
8789
MIN_INT64 = MIN_INT64,
8890
MAX_INT = MAX_INT,
8991
MIN_INT = MIN_INT,
92+
MAX_STR_LEN = MAX_STR_LEN,
9093

9194
-- FDP.
9295
random_locale = random_locale,

tests/lapi/string_byte_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ local test_lib = require("lib")
1717
local function TestOneInput(buf, _size)
1818
local fdp = luzer.FuzzedDataProvider(buf)
1919
os.setlocale(test_lib.random_locale(fdp), "all")
20-
local max_len = fdp:consume_integer(0, test_lib.MAX_INT)
21-
local str = fdp:consume_string(max_len)
20+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
2221
local i = fdp:consume_integer(0, test_lib.MAX_INT)
2322
local j = fdp:consume_integer(0, test_lib.MAX_INT)
2423
assert(string.byte(str, i, j) == str:byte(i, j))

tests/lapi/string_dump_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ local test_lib = require("lib")
2020
local function TestOneInput(buf, _size)
2121
local fdp = luzer.FuzzedDataProvider(buf)
2222
os.setlocale(test_lib.random_locale(fdp), "all")
23-
local max_len = fdp:consume_string(1, test_lib.MAX_INT)
24-
local str = fdp:consume_string(1, max_len)
23+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
2524
local strip = fdp:consume_boolean()
2625
local ok, func = pcall(loadstring, str)
2726
if not ok or func == nil then

tests/lapi/string_find_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ local test_lib = require("lib")
2323
local function TestOneInput(buf, _size)
2424
local fdp = luzer.FuzzedDataProvider(buf)
2525
os.setlocale(test_lib.random_locale(fdp), "all")
26-
local max_len = fdp:consume_integer(0, test_lib.MAX_INT)
27-
local str = fdp:consume_string(max_len)
28-
local pattern = fdp:consume_string(max_len)
26+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
27+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
2928
local init = fdp:consume_integer(0, test_lib.MAX_INT)
3029
local plain = fdp:consume_boolean()
3130
-- Avoid errors like "malformed pattern (missing ']')".

tests/lapi/string_format_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ local function TestOneInput(buf, _size)
6767
local fdp = luzer.FuzzedDataProvider(buf)
6868
local spec = fdp:oneof(specifiers)
6969
local format_string = ("%%%s"):format(spec)
70-
local max_len = fdp:consume_integer(1, 10000)
71-
local str = fdp:consume_string(1, max_len)
70+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
7271

7372
os.setlocale(test_lib.random_locale(fdp), "all")
7473
local ok, res = pcall(string.format, format_string, str)

tests/lapi/string_gmatch_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ local test_lib = require("lib")
2121
local function TestOneInput(buf, _size)
2222
local fdp = luzer.FuzzedDataProvider(buf)
2323
os.setlocale(test_lib.random_locale(fdp), "all")
24-
local len = fdp:consume_integer(0, test_lib.MAX_INT)
25-
local s = fdp:consume_string(len)
26-
local pattern = fdp:consume_string(len)
24+
local s = fdp:consume_string(test_lib.MAX_STR_LEN)
25+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
2726
local init = fdp:consume_integer(0, test_lib.MAX_INT)
2827
string.gmatch(s, pattern, init)
2928
end

tests/lapi/string_gsub_test.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ local test_lib = require("lib")
2323

2424
local function TestOneInput(buf, _size)
2525
local fdp = luzer.FuzzedDataProvider(buf)
26-
local max_len = fdp:consume_string(0, test_lib.MAX_INT)
27-
local str = fdp:consume_string(0, max_len)
28-
local pattern = fdp:consume_string(0, max_len)
29-
local repl = fdp:consume_string(0, max_len)
26+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
27+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
28+
local repl = fdp:consume_string(test_lib.MAX_STR_LEN)
3029
local n = fdp:consume_integer(0, test_lib.MAX_INT)
3130

3231
os.setlocale(test_lib.random_locale(fdp), "all")

tests/lapi/string_len_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ local test_lib = require("lib")
1414
local function TestOneInput(buf, _size)
1515
local fdp = luzer.FuzzedDataProvider(buf)
1616
os.setlocale(test_lib.random_locale(fdp), "all")
17-
local str_len = fdp:consume_integer(0, test_lib.MAX_INT)
18-
local str = fdp:consume_string(str_len)
17+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
1918
assert(string.len(str) == #str)
2019
end
2120

tests/lapi/string_match_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ local test_lib = require("lib")
1414
local function TestOneInput(buf, _size)
1515
local fdp = luzer.FuzzedDataProvider(buf)
1616
os.setlocale(test_lib.random_locale(fdp), "all")
17-
local max_len = fdp:consume_integer(0, test_lib.MAX_INT)
18-
local str = fdp:consume_string(max_len)
19-
local pattern = fdp:consume_string(max_len)
17+
local str = fdp:consume_string(test_lib.MAX_STR_LEN)
18+
local pattern = fdp:consume_string(test_lib.MAX_STR_LEN)
2019
local init = fdp:consume_integer(0, test_lib.MAX_INT)
2120
-- Avoid errors like "malformed pattern (ends with '%')".
2221
local ok, res = pcall(string.match, str, pattern, init)

tests/lapi/string_pack_test.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Synopsis: string.pack(fmt, v1, v2, ...)
1111
local luzer = require("luzer")
1212
local test_lib = require("lib")
1313

14-
-- PUC Rio Lua only.
15-
if test_lib.lua_version() == "LuaJIT" then
14+
-- The function `string.pack()` is available since Lua 5.3.
15+
local _, version_major, version_minor = test_lib.lua_version()
16+
if version_major <= 5 and version_minor < 3 then
17+
print("Unsupported version.")
1618
os.exit(0)
1719
end
1820

@@ -24,7 +26,7 @@ local function TestOneInput(buf, _size)
2426
return -1
2527
end
2628
local n = fdp:consume_integer(1, test_lib.MAX_INT)
27-
local values = fdp:consume_strings(test_lib.MAX_INT, n)
29+
local values = fdp:consume_strings(test_lib.MAX_STR_LEN, n)
2830
string.pack(fmt_str, table.unpack(values))
2931
end
3032

0 commit comments

Comments
 (0)