aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/WordComposer.java
diff options
context:
space:
mode:
authorXiaojun Bi <bxj@google.com>2014-04-18 10:52:15 -0700
committerXiaojun Bi <bxj@google.com>2014-04-18 14:56:35 -0700
commit11b707616800e08891f6b610be90033acda8ffd0 (patch)
treeee82737e77f4ee0b60ae6aed1c9544181cc98faa /java/src/com/android/inputmethod/latin/WordComposer.java
parent7cb0cc1b29ebca17933ac4b7fabc80f04d17a767 (diff)
downloadlatinime-11b707616800e08891f6b610be90033acda8ffd0.tar.gz
latinime-11b707616800e08891f6b610be90033acda8ffd0.tar.xz
latinime-11b707616800e08891f6b610be90033acda8ffd0.zip
Fix a bug for counting code points in WordComposer.java
This bug threw an ArrayIndexOutOfBoundsException when the word length is 49 (maxSize + 1) when calling StringUtils.copyCodePointsAndReturnCodePointCount(...) in the same function. This bug is discovered by running SKETCH. The intent is to count the code points from index 0 to index i (included). The original code only counted the code points from index 0 to index (i-1). Bug: 13969542 Change-Id: Idbf596aba2379ba552dbe580c83c42044d505aaf
Diffstat (limited to 'java/src/com/android/inputmethod/latin/WordComposer.java')
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 1268e5aac..d755195f2 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -129,22 +129,25 @@ public final class WordComposer {
* -1 is returned.
*
* @param destination the array of ints.
- * @param maxSize the size of the array.
* @return the number of copied code points.
*/
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
- final int[] destination, final int maxSize) {
- final int i = mTypedWordCache.length() - 1 - trailingSingleQuotesCount();
- if (i < 0) {
+ final int[] destination) {
+ // lastIndex is exclusive
+ final int lastIndex = mTypedWordCache.length() - trailingSingleQuotesCount();
+ if (lastIndex <= 0) {
// The string is empty or contains only single quotes.
return 0;
}
- final int codePointSize = Character.codePointCount(mTypedWordCache, 0, i);
- if (codePointSize > maxSize) {
+
+ // The following function counts the number of code points in the text range which begins
+ // at index 0 and extends to the character at lastIndex.
+ final int codePointSize = Character.codePointCount(mTypedWordCache, 0, lastIndex);
+ if (codePointSize > destination.length) {
return -1;
}
return StringUtils.copyCodePointsAndReturnCodePointCount(destination, mTypedWordCache, 0,
- i + 1, true /* downCase */);
+ lastIndex, true /* downCase */);
}
public boolean isSingleLetter() {