diff options
author | 2013-08-19 10:04:29 +0000 | |
---|---|---|
committer | 2013-08-19 10:04:29 +0000 | |
commit | 63155dfa7782b314d18bc8f1a95440b1470838fe (patch) | |
tree | 8f99fdb53eed284fb8e17f38dee3152fb5ba4748 | |
parent | c8fb03e6a8859f29a51ca6aefdd9a5be9101bd3f (diff) | |
parent | 4a65258bc7c284ecf61ba6e4399a7012e71d7952 (diff) | |
download | latinime-63155dfa7782b314d18bc8f1a95440b1470838fe.tar.gz latinime-63155dfa7782b314d18bc8f1a95440b1470838fe.tar.xz latinime-63155dfa7782b314d18bc8f1a95440b1470838fe.zip |
Merge "Fix possible SIGSEGV."
-rw-r--r-- | native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h | 4 | ||||
-rw-r--r-- | native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h index 45c7f5cf9..74eb5dfe7 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_output.h @@ -49,8 +49,10 @@ class DicNodeStateOutput { void addMergedNodeCodePoints(const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) { if (mergedNodeCodePoints) { + const int additionalCodePointCount = min(static_cast<int>(mergedNodeCodePointCount), + MAX_WORD_LENGTH - mOutputtedCodePointCount); memcpy(&mCodePointsBuf[mOutputtedCodePointCount], mergedNodeCodePoints, - mergedNodeCodePointCount * sizeof(mCodePointsBuf[0])); + additionalCodePointCount * sizeof(mCodePointsBuf[0])); mOutputtedCodePointCount = static_cast<uint16_t>( mOutputtedCodePointCount + mergedNodeCodePointCount); if (mOutputtedCodePointCount < MAX_WORD_LENGTH) { diff --git a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h index 5854f4f6e..f437c95f6 100644 --- a/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h +++ b/native/jni/src/suggest/core/dicnode/internal/dic_node_state_prevword.h @@ -69,11 +69,14 @@ class DicNodeStatePrevWord { const int prevWordNodePos, const int *const src0, const int16_t length0, const int *const src1, const int16_t length1, const int *const prevSpacePositions, const int lastInputIndex) { - mPrevWordCount = prevWordCount; + mPrevWordCount = min(prevWordCount, static_cast<int16_t>(MAX_RESULTS)); mPrevWordProbability = prevWordProbability; mPrevWordNodePos = prevWordNodePos; - const int twoWordsLen = + int twoWordsLen = DicNodeUtils::appendTwoWords(src0, length0, src1, length1, mPrevWord); + if (twoWordsLen >= MAX_WORD_LENGTH) { + twoWordsLen = MAX_WORD_LENGTH - 1; + } mPrevWord[twoWordsLen] = KEYCODE_SPACE; mPrevWordStart = length0; mPrevWordLength = static_cast<int16_t>(twoWordsLen + 1); |