diff options
author | 2013-08-23 04:05:25 -0700 | |
---|---|---|
committer | 2013-08-23 04:05:25 -0700 | |
commit | b6a70ead78177a913e777ca6ee9660ee7ca25bab (patch) | |
tree | 9b68ca142df3a4843dbaa8e6119ff426a34ec12c | |
parent | 44579790ade93972f972f6d8adee6c1af82f061c (diff) | |
parent | b64157bf4720dfc2aa40ad8e6806459012f81082 (diff) | |
download | latinime-b6a70ead78177a913e777ca6ee9660ee7ca25bab.tar.gz latinime-b6a70ead78177a913e777ca6ee9660ee7ca25bab.tar.xz latinime-b6a70ead78177a913e777ca6ee9660ee7ca25bab.zip |
am b64157bf: Merge "Fix: reading uninitialized area."
* commit 'b64157bf4720dfc2aa40ad8e6806459012f81082':
Fix: reading uninitialized area.
-rw-r--r-- | native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp index 3000860a3..11da03951 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp @@ -126,7 +126,7 @@ int DynamicPatriciaTriePolicy::getTerminalNodePositionOfWord(const int *const in int pos = getRootPosition(); DynamicPatriciaTrieNodeReader nodeReader(mDictRoot, getBigramsStructurePolicy(), getShortcutsStructurePolicy()); - while (currentLength <= length) { + while (currentLength < length) { // When foundMatchedNode becomes true, currentLength is increased at least once. bool foundMatchedNode = false; int totalChildCount = 0; @@ -144,13 +144,15 @@ int DynamicPatriciaTriePolicy::getTerminalNodePositionOfWord(const int *const in for (int i = 0; i < childCount; i++) { nodeReader.fetchNodeInfoFromBufferAndGetNodeCodePoints(pos, MAX_WORD_LENGTH, mergedNodeCodePoints); - if (nodeReader.isDeleted() || nodeReader.getCodePointCount() <= 0) { + const int nodeCodePointCount = nodeReader.getCodePointCount(); + if (nodeReader.isDeleted() || nodeCodePointCount <= 0 + || currentLength + nodeCodePointCount > length) { // Skip deleted or empty node. pos = nodeReader.getSiblingNodePos(); continue; } bool matched = true; - for (int j = 0; j < nodeReader.getCodePointCount(); ++j) { + for (int j = 0; j < nodeCodePointCount; ++j) { if (mergedNodeCodePoints[j] != searchCodePoints[currentLength + j]) { // Different code point is found. matched = false; @@ -158,7 +160,7 @@ int DynamicPatriciaTriePolicy::getTerminalNodePositionOfWord(const int *const in } } if (matched) { - currentLength += nodeReader.getCodePointCount(); + currentLength += nodeCodePointCount; if (length == currentLength) { // Terminal position is found. return nodeReader.getNodePos(); |