Fix for IndexOutOfBounds in TextView getWordLimitsAt.

Bug http://b/issue?id=2948904

Change-Id: I10008374da92d5a98ec567cc76732383e66c4c5b
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 8ab8f9d..248f6eb 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -7047,14 +7047,14 @@
             return -1;
         }
 
-        int end = offset;
+        int len = mText.length();
+        int end = Math.min(offset, len);
 
         if (end < 0) {
             return -1;
         }
 
         int start = end;
-        int len = mText.length();
 
         for (; start > 0; start--) {
             char c = mTransformed.charAt(start - 1);