diff options
author | 2009-10-14 16:10:32 -0700 | |
---|---|---|
committer | 2009-10-14 16:30:34 -0700 | |
commit | d0e43ecb34d166f9965c2e512fc3540c42482ac4 (patch) | |
tree | 7f29b98de9562e182aaac8e1ef7fa7d8969dfee7 | |
parent | dd8c1d8db320dde6bb6ae17189e4750dba239503 (diff) | |
download | latinime-d0e43ecb34d166f9965c2e512fc3540c42482ac4.tar.gz latinime-d0e43ecb34d166f9965c2e512fc3540c42482ac4.tar.xz latinime-d0e43ecb34d166f9965c2e512fc3540c42482ac4.zip |
Fix for #2185627 : ArrayIndexOutOfBounds in BinaryDictionary.getWords()
Make sure the word count doesn't exceed the maximum suggested words.
And also, only get the count one time instead of every time a match
is found.
-rw-r--r-- | dictionary/src/dictionary.cpp | 12 | ||||
-rw-r--r-- | dictionary/src/dictionary.h | 1 |
2 files changed, 6 insertions, 7 deletions
diff --git a/dictionary/src/dictionary.cpp b/dictionary/src/dictionary.cpp index fe5b4dc53..306aff527 100644 --- a/dictionary/src/dictionary.cpp +++ b/dictionary/src/dictionary.cpp @@ -51,6 +51,7 @@ Dictionary::~Dictionary() int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies, int maxWordLength, int maxWords, int maxAlternatives, int skipPos) { + int suggWords; mFrequencies = frequencies; mOutputChars = outWords; mInputCodes = codes; @@ -58,14 +59,16 @@ int Dictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWor mMaxAlternatives = maxAlternatives; mMaxWordLength = maxWordLength; mMaxWords = maxWords; - mWords = 0; mSkipPos = skipPos; mMaxEditDistance = mInputLength < 5 ? 2 : mInputLength / 2; getWordsRec(0, 0, mInputLength * 3, false, 1, 0, 0); - if (DEBUG_DICT) LOGI("Returning %d words", mWords); - return mWords; + // Get the word count + suggWords = 0; + while (suggWords < mMaxWords && mFrequencies[suggWords] > 0) suggWords++; + if (DEBUG_DICT) LOGI("Returning %d words", suggWords); + return suggWords; } unsigned short @@ -138,9 +141,6 @@ Dictionary::addWord(unsigned short *word, int length, int frequency) *dest++ = *word++; } *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); return true; } diff --git a/dictionary/src/dictionary.h b/dictionary/src/dictionary.h index 8f195ca9a..a12c035c8 100644 --- a/dictionary/src/dictionary.h +++ b/dictionary/src/dictionary.h @@ -60,7 +60,6 @@ private: int *mFrequencies; int mMaxWords; int mMaxWordLength; - int mWords; unsigned short *mOutputChars; int *mInputCodes; int mInputLength; |