Fix a crash when MAX_WORD_LENGTH is too short.
Change-Id: Idcb5aa2685321b8d0ac7d846caecbd1c79e4dd77main
parent
48e432ceb8
commit
f5cded1c6c
|
@ -170,12 +170,12 @@ public class BinaryDictionary extends Dictionary {
|
||||||
mOutputChars_bigrams, mFrequencies_bigrams, MAX_WORD_LENGTH, MAX_BIGRAMS,
|
mOutputChars_bigrams, mFrequencies_bigrams, MAX_WORD_LENGTH, MAX_BIGRAMS,
|
||||||
MAX_ALTERNATIVES);
|
MAX_ALTERNATIVES);
|
||||||
|
|
||||||
for (int j = 0; j < count; j++) {
|
for (int j = 0; j < count; ++j) {
|
||||||
if (mFrequencies_bigrams[j] < 1) break;
|
if (mFrequencies_bigrams[j] < 1) break;
|
||||||
int start = j * MAX_WORD_LENGTH;
|
final int start = j * MAX_WORD_LENGTH;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while (mOutputChars_bigrams[start + len] != 0) {
|
while (len < MAX_WORD_LENGTH && mOutputChars_bigrams[start + len] != 0) {
|
||||||
len++;
|
++len;
|
||||||
}
|
}
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
callback.addWord(mOutputChars_bigrams, start, len, mFrequencies_bigrams[j],
|
callback.addWord(mOutputChars_bigrams, start, len, mFrequencies_bigrams[j],
|
||||||
|
@ -204,12 +204,12 @@ public class BinaryDictionary extends Dictionary {
|
||||||
mFrequencies, nextLettersFrequencies,
|
mFrequencies, nextLettersFrequencies,
|
||||||
nextLettersFrequencies != null ? nextLettersFrequencies.length : 0);
|
nextLettersFrequencies != null ? nextLettersFrequencies.length : 0);
|
||||||
|
|
||||||
for (int j = 0; j < count; j++) {
|
for (int j = 0; j < count; ++j) {
|
||||||
if (mFrequencies[j] < 1) break;
|
if (mFrequencies[j] < 1) break;
|
||||||
int start = j * MAX_WORD_LENGTH;
|
final int start = j * MAX_WORD_LENGTH;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while (mOutputChars[start + len] != 0) {
|
while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
|
||||||
len++;
|
++len;
|
||||||
}
|
}
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
|
callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
|
||||||
|
|
|
@ -146,7 +146,7 @@ void BigramDictionary::searchForTerminalNode(int addressLookingFor, int frequenc
|
||||||
bool firstAddress = true;
|
bool firstAddress = true;
|
||||||
bool haveToSearchAll = true;
|
bool haveToSearchAll = true;
|
||||||
|
|
||||||
if (depth >= 0) {
|
if (depth < MAX_WORD_LENGTH && depth >= 0) {
|
||||||
word[depth] = (unsigned short) followingChar;
|
word[depth] = (unsigned short) followingChar;
|
||||||
}
|
}
|
||||||
pos = followDownBranchAddress; // pos start at count
|
pos = followDownBranchAddress; // pos start at count
|
||||||
|
|
|
@ -50,8 +50,12 @@
|
||||||
#define SUGGEST_MISSING_CHARACTERS true
|
#define SUGGEST_MISSING_CHARACTERS true
|
||||||
#define SUGGEST_MISSING_CHARACTERS_THRESHOLD 5
|
#define SUGGEST_MISSING_CHARACTERS_THRESHOLD 5
|
||||||
|
|
||||||
#define MAX_WORD_LENGTH_INTERNAL 64
|
// This should be greater than or equal to MAX_WORD_LENGTH defined in BinaryDictionary.java
|
||||||
|
// This is only used for the size of array. Not to be used in c functions.
|
||||||
|
#define MAX_WORD_LENGTH_INTERNAL 48
|
||||||
|
|
||||||
#define MAX_DEPTH_MULTIPLIER 3
|
#define MAX_DEPTH_MULTIPLIER 3
|
||||||
|
|
||||||
|
#define min(a,b) ((a)<(b)?(a):(b))
|
||||||
|
|
||||||
#endif // LATINIME_DEFINES_H
|
#endif // LATINIME_DEFINES_H
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define LOG_TAG "LatinIME: unigram_dictionary.cpp"
|
#define LOG_TAG "LatinIME: unigram_dictionary.cpp"
|
||||||
|
@ -78,6 +78,7 @@ int UnigramDictionary::getSuggestions(int *codes, int codesSize, unsigned short
|
||||||
|
|
||||||
void UnigramDictionary::initSuggestions(int *codes, int codesSize, unsigned short *outWords,
|
void UnigramDictionary::initSuggestions(int *codes, int codesSize, unsigned short *outWords,
|
||||||
int *frequencies) {
|
int *frequencies) {
|
||||||
|
if (DEBUG_DICT) LOGI("initSuggest");
|
||||||
mFrequencies = frequencies;
|
mFrequencies = frequencies;
|
||||||
mOutputChars = outWords;
|
mOutputChars = outWords;
|
||||||
mInputCodes = codes;
|
mInputCodes = codes;
|
||||||
|
@ -87,6 +88,7 @@ void UnigramDictionary::initSuggestions(int *codes, int codesSize, unsigned shor
|
||||||
|
|
||||||
int UnigramDictionary::getSuggestionCandidates(int inputLength, int skipPos,
|
int UnigramDictionary::getSuggestionCandidates(int inputLength, int skipPos,
|
||||||
int *nextLetters, int nextLettersSize) {
|
int *nextLetters, int nextLettersSize) {
|
||||||
|
if (DEBUG_DICT) LOGI("getSuggestionCandidates");
|
||||||
int initialPos = 0;
|
int initialPos = 0;
|
||||||
if (IS_LATEST_DICT_VERSION) {
|
if (IS_LATEST_DICT_VERSION) {
|
||||||
initialPos = DICTIONARY_HEADER_SIZE;
|
initialPos = DICTIONARY_HEADER_SIZE;
|
||||||
|
@ -115,6 +117,10 @@ bool UnigramDictionary::addWord(unsigned short *word, int length, int frequency)
|
||||||
for (int i = 0; i <= length; i++) s[i] = word[i];
|
for (int i = 0; i <= length; i++) s[i] = word[i];
|
||||||
LOGI("Found word = %s, freq = %d : \n", s, frequency);
|
LOGI("Found word = %s, freq = %d : \n", s, frequency);
|
||||||
}
|
}
|
||||||
|
if (length > MAX_WORD_LENGTH) {
|
||||||
|
if (DEBUG_DICT) LOGI("Exceeded max word length.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the right insertion point
|
// Find the right insertion point
|
||||||
int insertAt = 0;
|
int insertAt = 0;
|
||||||
|
@ -177,7 +183,8 @@ void UnigramDictionary::getWords(const int initialPos, const int inputLength, co
|
||||||
int *nextLetters, const int nextLettersSize) {
|
int *nextLetters, const int nextLettersSize) {
|
||||||
int initialPosition = initialPos;
|
int initialPosition = initialPos;
|
||||||
const int count = Dictionary::getCount(DICT, &initialPosition);
|
const int count = Dictionary::getCount(DICT, &initialPosition);
|
||||||
getWordsRec(count, initialPosition, 0, inputLength * MAX_DEPTH_MULTIPLIER,
|
getWordsRec(count, initialPosition, 0,
|
||||||
|
min(inputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH),
|
||||||
mInputLength <= 0, 1, 0, 0, skipPos, nextLetters, nextLettersSize);
|
mInputLength <= 0, 1, 0, 0, skipPos, nextLetters, nextLettersSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue