From 4e55dac82d78282ecf394effac955dbcfaa124db Mon Sep 17 00:00:00 2001 From: "scott%scott-macgregor.org" Date: Thu, 26 Aug 2004 03:32:11 +0000 Subject: [PATCH] Bug #240819 --> Crash in mail.dll when checking mail - TB073 [@ nsTransform2D::SetToIdentity ] Fix a potential divide by zero floating point operation in the bayesian algorithm to hopefully prevent a top crash. git-svn-id: svn://10.0.0.236/trunk@161297 18797224-902f-48f8-a5cc-f745e15eee43 --- .../bayesian-spam-filter/src/nsBayesianFilter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mozilla/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp b/mozilla/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp index 17ba1df4400..1b209fc32c1 100644 --- a/mozilla/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp +++ b/mozilla/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp @@ -979,7 +979,14 @@ void nsBayesianFilter::classifyMessage(Tokenizer& tokenizer, const char* message double hamcount = ((t != NULL) ? t->mCount : 0); t = mBadTokens.get(word); double spamcount = ((t != NULL) ? t->mCount : 0); - prob = (spamcount / nbad) / ( hamcount / ngood + spamcount / nbad); + + // if hamcount and spam count are both 0, we could end up with a divide by 0 error, + // tread carefully here. (Bug #240819) + double probDenom = (hamcount *nbad + spamcount*ngood); + if (probDenom == 0.0) // nGood and nbad are known to be non zero or we wouldn't be here + probDenom = nbad + ngood; // error case use a value of 1 for hamcount and spamcount if they are both zero. + + prob = (spamcount * ngood)/probDenom; double n = hamcount + spamcount; prob = (0.225 + n * prob) / (.45 + n); double distance = PR_ABS(prob - 0.5);