From: Vsevolod Stakhov Date: Sat, 6 Dec 2025 08:47:32 +0000 (+0000) Subject: [Test] Fix additional Lua 5.4 compatibility issues in fuzz tests X-Git-Tag: 3.14.2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df898c58daf4ac45bc04ba48bb7323c90dbe55e0;p=thirdparty%2Frspamd.git [Test] Fix additional Lua 5.4 compatibility issues in fuzz tests - base32.lua: Add cdata_to_number helper for size_t conversion - rfc2047.lua: Use math.floor for string.sub indices (Lua 5.4 requires integers) --- diff --git a/test/lua/unit/base32.lua b/test/lua/unit/base32.lua index e6eaf7f686..c49d9ff9fd 100644 --- a/test/lua/unit/base32.lua +++ b/test/lua/unit/base32.lua @@ -14,6 +14,13 @@ context("Base32 encodning", function() int memcmp(const void *a1, const void *a2, size_t len); ]] + -- Helper to convert cdata numbers to Lua numbers (cffi-lua compatibility) + local function cdata_to_number(v) + local n = tonumber(v) + if n then return n end + return tonumber(tostring(v):match("^(%d+)")) + end + local function random_buf(max_size) local l = ffi.C.ottery_rand_unsigned() % max_size + 1 local buf = ffi.new("unsigned char[?]", l) @@ -47,7 +54,7 @@ context("Base32 encodning", function() local nl = ffi.new("size_t [1]") local nb = ffi.C.rspamd_decode_base32(bs, #bs, nl, how) - local reported_len = tonumber(nl[0]) or 0 + local reported_len = cdata_to_number(nl[0]) or 0 assert_equal(reported_len, l, string.format("invalid size reported: %s reported vs %s expected", tostring(reported_len), tostring(l))) local cmp = ffi.C.memcmp(b, nb, l) diff --git a/test/lua/unit/rfc2047.lua b/test/lua/unit/rfc2047.lua index 7f341fa363..b65b67b5e2 100644 --- a/test/lua/unit/rfc2047.lua +++ b/test/lua/unit/rfc2047.lua @@ -72,8 +72,9 @@ context("RFC2047 decoding", function() for _ = 0,1000 do local r1 = math.random() local r2 = math.random() - local sl1 = #str / 2.0 * r1 - local sl2 = #str / 2.0 * r2 + -- Use math.floor for Lua 5.4 compatibility (string.sub requires integers) + local sl1 = math.floor(#str / 2.0 * r1) + local sl2 = math.floor(#str / 2.0 * r2) local s1 = tostring(util.encode_base64(string.sub(str, 1, sl1))) local s2 = tostring(util.encode_base64(string.sub(str, sl1 + 1, sl2)))