From c11846f7897fcbe71bac3b7435a387704e74935e Mon Sep 17 00:00:00 2001 From: "timeless%mozdev.org" Date: Wed, 2 Nov 2005 16:56:58 +0000 Subject: [PATCH] Bug 207057 Division by zero in UCDET.DLL r=smontagu sr=rbs --- .../src/base/CharDistribution.cpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/extensions/universalchardet/src/base/CharDistribution.cpp b/extensions/universalchardet/src/base/CharDistribution.cpp index f15272d93b2..9dd4d902fc9 100644 --- a/extensions/universalchardet/src/base/CharDistribution.cpp +++ b/extensions/universalchardet/src/base/CharDistribution.cpp @@ -44,25 +44,24 @@ #include "EUCTWFreq.tab" #include "GB2312Freq.tab" -#define SURE_YES ((float)0.99) -#define SURE_NO ((float)0.01) +#define SURE_YES 0.99f +#define SURE_NO 0.01f //return confidence base on received data float CharDistributionAnalysis::GetConfidence() { - float r; + //if we didn't receive any character in our consideration range, return negative answer + if (mTotalChars <= 0) + return SURE_NO; - if (mTotalChars > 0) - { - r = mFreqChars / (float)(mTotalChars - mFreqChars) / mTypicalDistributionRatio; - //normalize confidence, (and we don't want to be 100% sure) - if (r >= (float)1.00) - r = SURE_YES; + if (mTotalChars != mFreqChars) { + float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio); + + if (r < SURE_YES) + return r; } - else //if we didn't receive any character in our consideration range, return negative answer - r = SURE_NO; - - return r; + //normalize confidence, (we don't want to be 100% sure) + return SURE_YES; } EUCTWDistributionAnalysis::EUCTWDistributionAnalysis()