A bug fix for the mistyped space algorithm
Bug: 3311719
-- also fixed compiler warnings
Change-Id: I6941c0d02f10d67af88bc943748dde8d8783fabb
diff --git a/native/src/defines.h b/native/src/defines.h
index 16927e5..a81aa49 100644
--- a/native/src/defines.h
+++ b/native/src/defines.h
@@ -103,7 +103,7 @@
#define U_SHORT_MAX 1 << 16
#endif
#ifndef S_INT_MAX
-#define S_INT_MAX ((1 << 31) - 1)
+#define S_INT_MAX 2147483647 // ((1 << 31) - 1)
#endif
// Define this to use mmap() for dictionary loading. Undefine to use malloc() instead of mmap().
diff --git a/native/src/proximity_info.cpp b/native/src/proximity_info.cpp
index 5f2d09f..102123c 100644
--- a/native/src/proximity_info.cpp
+++ b/native/src/proximity_info.cpp
@@ -42,7 +42,7 @@
}
inline int ProximityInfo::getStartIndexFromCoordinates(const int x, const int y) const {
- return (y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH)
+ return ((y / CELL_HEIGHT) * GRID_WIDTH + (x / CELL_WIDTH))
* MAX_PROXIMITY_CHARS_SIZE;
}
diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp
index 3487d4f..c2cd760 100644
--- a/native/src/unigram_dictionary.cpp
+++ b/native/src/unigram_dictionary.cpp
@@ -81,7 +81,7 @@
void UnigramDictionary::getWordWithDigraphSuggestionsRec(const ProximityInfo *proximityInfo,
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
const int codesBufferSize, const int flags, const int* codesSrc, const int codesRemain,
- int currentDepth, int* codesDest, unsigned short* outWords, int* frequencies) {
+ const int currentDepth, int* codesDest, unsigned short* outWords, int* frequencies) {
if (currentDepth < MAX_UMLAUT_SEARCH_DEPTH) {
for (int i = 0; i < codesRemain; ++i) {
@@ -232,11 +232,9 @@
if (DEBUG_PROXIMITY_INFO)
LOGI("Input[%d] x = %d, y = %d, has space proximity = %d",
i, x, y, proximityInfo->hasSpaceProximity(x, y));
-
if (proximityInfo->hasSpaceProximity(x, y)) {
getMistypedSpaceWords(mInputLength, i);
}
-
}
}
PROF_END(6);
@@ -405,7 +403,7 @@
const int secondWordLength) {
if (inputLength >= MAX_WORD_LENGTH) return false;
if (0 >= firstWordLength || 0 >= secondWordLength || firstWordStartPos >= secondWordStartPos
- || firstWordStartPos < 0 || secondWordStartPos >= inputLength)
+ || firstWordStartPos < 0 || secondWordStartPos + secondWordLength > inputLength)
return false;
const int newWordLength = firstWordLength + secondWordLength + 1;
// Allocating variable length array on stack
@@ -487,7 +485,7 @@
}
}
-static const int TWO_31ST_DIV_255 = ((1 << 31) - 1) / 255;
+static const int TWO_31ST_DIV_255 = S_INT_MAX / 255;
static inline int capped255MultForFullMatchAccentsOrCapitalizationDifference(const int num) {
return (num < TWO_31ST_DIV_255 ? 255 * num : S_INT_MAX);
}
diff --git a/native/src/unigram_dictionary.h b/native/src/unigram_dictionary.h
index ef820cb..3d3007c 100644
--- a/native/src/unigram_dictionary.h
+++ b/native/src/unigram_dictionary.h
@@ -46,7 +46,7 @@
void getWordWithDigraphSuggestionsRec(const ProximityInfo *proximityInfo,
const int *xcoordinates, const int* ycoordinates, const int *codesBuffer,
const int codesBufferSize, const int flags, const int* codesSrc, const int codesRemain,
- int currentDepth, int* codesDest, unsigned short* outWords, int* frequencies);
+ const int currentDepth, int* codesDest, unsigned short* outWords, int* frequencies);
void initSuggestions(const int *codes, const int codesSize, unsigned short *outWords,
int *frequencies);
void getSuggestionCandidates(const int skipPos, const int excessivePos,
@@ -113,7 +113,7 @@
const int FULL_WORD_MULTIPLIER;
const int ROOT_POS;
const unsigned int BYTES_IN_ONE_CHAR;
- const unsigned int MAX_UMLAUT_SEARCH_DEPTH;
+ const int MAX_UMLAUT_SEARCH_DEPTH;
// Flags for special processing
// Those *must* match the flags in BinaryDictionary.Flags.ALL_FLAGS in BinaryDictionary.java