OSDN Git Service

Avoid a crash trying to get a substring whose start is after its end.
authorEric Fischer <enf@google.com>
Tue, 15 Dec 2009 01:33:11 +0000 (17:33 -0800)
committerEric Fischer <enf@google.com>
Tue, 15 Dec 2009 01:35:36 +0000 (17:35 -0800)
Constrain the start of the extracted text, not just the end, to the length
of the content.

Approver: ryanpc
Bug: 2323813

core/java/android/widget/TextView.java

index bcdefb3..cdaba8a 100644 (file)
@@ -4531,6 +4531,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                     // Now use the delta to determine the actual amount of text
                     // we need.
                     partialEndOffset += delta;
+                    if (partialStartOffset > N) {
+                        partialStartOffset = N;
+                    } else if (partialStartOffset < 0) {
+                        partialStartOffset = 0;
+                    }
                     if (partialEndOffset > N) {
                         partialEndOffset = N;
                     } else if (partialEndOffset < 0) {