am 4611b578: Merge change I6c27819c into eclair-mr2

Merge commit '4611b578a1f20502688f004e8cfc3ebe3a0a64bd' into eclair-mr2-plus-aosp

* commit '4611b578a1f20502688f004e8cfc3ebe3a0a64bd':
  Fix for #2185627 : ArrayIndexOutOfBounds in BinaryDictionary.getWords()
This commit is contained in:
Amith Yamasani 2009-10-14 16:50:58 -07:00 committed by Android Git Automerger
commit 1bf6558702
2 changed files with 6 additions and 7 deletions

View file

@ -51,6 +51,7 @@ Dictionary::~Dictionary()
int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies,
int maxWordLength, int maxWords, int maxAlternatives, int skipPos) int maxWordLength, int maxWords, int maxAlternatives, int skipPos)
{ {
int suggWords;
mFrequencies = frequencies; mFrequencies = frequencies;
mOutputChars = outWords; mOutputChars = outWords;
mInputCodes = codes; mInputCodes = codes;
@ -58,14 +59,16 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor
mMaxAlternatives = maxAlternatives; mMaxAlternatives = maxAlternatives;
mMaxWordLength = maxWordLength; mMaxWordLength = maxWordLength;
mMaxWords = maxWords; mMaxWords = maxWords;
mWords = 0;
mSkipPos = skipPos; mSkipPos = skipPos;
mMaxEditDistance = mInputLength < 5 ? 2 : mInputLength / 2; mMaxEditDistance = mInputLength < 5 ? 2 : mInputLength / 2;
getWordsRec(0, 0, mInputLength * 3, false, 1, 0, 0); getWordsRec(0, 0, mInputLength * 3, false, 1, 0, 0);
if (DEBUG_DICT) LOGI("Returning %d words", mWords); // Get the word count
return mWords; suggWords = 0;
while (suggWords < mMaxWords && mFrequencies[suggWords] > 0) suggWords++;
if (DEBUG_DICT) LOGI("Returning %d words", suggWords);
return suggWords;
} }
unsigned short unsigned short
@ -138,9 +141,6 @@ Dictionary::addWord(unsigned short *word, int length, int frequency)
*dest++ = *word++; *dest++ = *word++;
} }
*dest = 0; // NULL terminate *dest = 0; // NULL terminate
// Update the word count
mWords = 0;
while (mFrequencies[mWords] > 0) mWords++;
if (DEBUG_DICT) LOGI("Added word at %d\n", insertAt); if (DEBUG_DICT) LOGI("Added word at %d\n", insertAt);
return true; return true;
} }

View file

@ -60,7 +60,6 @@ private:
int *mFrequencies; int *mFrequencies;
int mMaxWords; int mMaxWords;
int mMaxWordLength; int mMaxWordLength;
int mWords;
unsigned short *mOutputChars; unsigned short *mOutputChars;
int *mInputCodes; int *mInputCodes;
int mInputLength; int mInputLength;