aboutsummaryrefslogtreecommitdiffstats
path: root/native/src
diff options
context:
space:
mode:
Diffstat (limited to 'native/src')
-rw-r--r--native/src/bigram_dictionary.cpp2
-rw-r--r--native/src/defines.h6
-rw-r--r--native/src/unigram_dictionary.cpp11
3 files changed, 15 insertions, 4 deletions
diff --git a/native/src/bigram_dictionary.cpp b/native/src/bigram_dictionary.cpp
index 095b80531..7bfef38d3 100644
--- a/native/src/bigram_dictionary.cpp
+++ b/native/src/bigram_dictionary.cpp
@@ -146,7 +146,7 @@ void BigramDictionary::searchForTerminalNode(int addressLookingFor, int frequenc
bool firstAddress = true;
bool haveToSearchAll = true;
- if (depth >= 0) {
+ if (depth < MAX_WORD_LENGTH && depth >= 0) {
word[depth] = (unsigned short) followingChar;
}
pos = followDownBranchAddress; // pos start at count
diff --git a/native/src/defines.h b/native/src/defines.h
index 953905fb2..8b817fbc1 100644
--- a/native/src/defines.h
+++ b/native/src/defines.h
@@ -50,8 +50,12 @@
#define SUGGEST_MISSING_CHARACTERS true
#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 min(a,b) ((a)<(b)?(a):(b))
+
#endif // LATINIME_DEFINES_H
diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp
index fa4e29632..707f1e6fb 100644
--- a/native/src/unigram_dictionary.cpp
+++ b/native/src/unigram_dictionary.cpp
@@ -16,8 +16,8 @@
*/
#include <assert.h>
-#include <stdio.h>
#include <fcntl.h>
+#include <stdio.h>
#include <string.h>
#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,
int *frequencies) {
+ if (DEBUG_DICT) LOGI("initSuggest");
mFrequencies = frequencies;
mOutputChars = outWords;
mInputCodes = codes;
@@ -87,6 +88,7 @@ void UnigramDictionary::initSuggestions(int *codes, int codesSize, unsigned shor
int UnigramDictionary::getSuggestionCandidates(int inputLength, int skipPos,
int *nextLetters, int nextLettersSize) {
+ if (DEBUG_DICT) LOGI("getSuggestionCandidates");
int initialPos = 0;
if (IS_LATEST_DICT_VERSION) {
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];
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
int insertAt = 0;
@@ -177,7 +183,8 @@ void UnigramDictionary::getWords(const int initialPos, const int inputLength, co
int *nextLetters, const int nextLettersSize) {
int initialPosition = initialPos;
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);
}