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.
This commit is contained in:
scott%scott-macgregor.org 2004-08-26 03:32:11 +00:00
Родитель 26b7c53bd7
Коммит 03878f136f
1 изменённых файлов: 8 добавлений и 1 удалений

Просмотреть файл

@ -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);