]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Use math.floor for Lua 5.4 integer division compatibility
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 6 Dec 2025 13:42:00 +0000 (13:42 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 6 Dec 2025 13:42:00 +0000 (13:42 +0000)
In Lua 5.4, the / operator always returns a float (2/2 = 1.0), while
LuaJIT returns an integer (2/2 = 1). This caused test dependency
registration to fail as tostring(i/2) produced "1.0" instead of "1".

test/functional/lua/limits.lua

index 52fb47fb9edd260f2c3a3acebdd802a266062489..e6bb2ce20e5f3b533283f7aa00e5b624deaa3317 100644 (file)
@@ -9,13 +9,15 @@ for _, i in ipairs(test_weights) do
   rspamd_config:register_symbol('GR_POSITIVE' .. tostring(i), 1.0, true_cb_gen())
 
   if i > 1 then
-    rspamd_config:register_dependency('GR_POSITIVE' .. tostring(i), 'GR_POSITIVE' .. tostring(i / 2))
+    local half = math.floor(i / 2)
+    rspamd_config:register_dependency('GR_POSITIVE' .. tostring(i), 'GR_POSITIVE' .. tostring(half))
   end
 
   rspamd_config:register_symbol('GR_NEGATIVE' .. tostring(i), 1.0, true_cb_gen())
 
   if i > 1 then
-    rspamd_config:register_dependency('GR_NEGATIVE' .. tostring(i), 'GR_NEGATIVE' .. tostring(i / 2))
+    local half = math.floor(i / 2)
+    rspamd_config:register_dependency('GR_NEGATIVE' .. tostring(i), 'GR_NEGATIVE' .. tostring(half))
   end
 end