]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Check for empty bayes results
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Nov 2018 15:43:08 +0000 (15:43 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Nov 2018 15:43:08 +0000 (15:43 +0000)
src/libstat/classifiers/bayes.c

index 1898df4fee3ded4bf0bbc47deb626625ceaa13ad..1a28a42cba6a0e5995890ca44902ea78812fd637 100644 (file)
@@ -329,6 +329,21 @@ bayes_classify (struct rspamd_classifier * ctx,
                bayes_classify_token (ctx, tok, &cl);
        }
 
+       if (cl.processed_tokens == 0) {
+               msg_info_bayes ("no tokens found in bayes database, ignore stats");
+
+               return TRUE;
+       }
+
+       if (ctx->cfg->min_tokens > 0 &&
+               cl.text_tokens < (gint)(ctx->cfg->min_tokens * 0.1)) {
+               msg_info_bayes ("ignore bayes probability since we have "
+                                               "too few text tokens: %uL, at least %d is required",
+                                               cl.text_tokens, (gint)(ctx->cfg->min_tokens * 0.1));
+
+               return TRUE;
+       }
+
        h = 1 - inv_chi_square (task, cl.spam_prob, cl.processed_tokens);
        s = 1 - inv_chi_square (task, cl.ham_prob, cl.processed_tokens);
 
@@ -368,17 +383,6 @@ bayes_classify (struct rspamd_classifier * ctx,
                }
        }
 
-       if (ctx->cfg->min_tokens > 0 &&
-                       cl.text_tokens < (gint)(ctx->cfg->min_tokens * 0.1)) {
-               msg_info_bayes ("ignore bayes probability %.2f since we have "
-                               "too few text tokens: %uL, at least %d is required",
-                               final_prob,
-                               cl.text_tokens,
-                               (gint)(ctx->cfg->min_tokens * 0.1));
-
-               return TRUE;
-       }
-
        pprob = rspamd_mempool_alloc (task->task_pool, sizeof (*pprob));
        *pprob = final_prob;
        rspamd_mempool_set_variable (task->task_pool, "bayes_prob", pprob, NULL);