]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Fix division by zero
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Mar 2018 13:35:40 +0000 (13:35 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 22 Mar 2018 13:35:58 +0000 (13:35 +0000)
src/plugins/lua/bayes_expiry.lua

index de848611a64b98e07e969d1ef7af5a0062c6b6e7..6ca22bd336571946a0b336c05b5aa9b59626bd3e 100644 (file)
@@ -183,8 +183,12 @@ local expiry_script = [[
   end
   redis.replicate_commands()
 
-  local mean = sum / nelts
-  local stddev = math.sqrt(sum_squares / nelts - mean * mean)
+  local mean, stddev = 0, 0
+
+  if nelts > 0 then
+    mean = sum / nelts
+    stddev = math.sqrt(sum_squares / nelts - mean * mean)
+  end
 
   for key,token in pairs(tokens) do
     local ham, spam, ttl = token[1], token[2], token[3]