OSDN Git Service

check offset and don't crash
authorMark Wagner <mxw@google.com>
Mon, 1 Mar 2010 17:24:59 +0000 (09:24 -0800)
committerMark Wagner <mxw@google.com>
Mon, 1 Mar 2010 17:28:29 +0000 (09:28 -0800)
core/java/android/text/TextUtils.java

index afb22ac..9589bf3 100644 (file)
@@ -1557,13 +1557,17 @@ public class TextUtils {
      * @param reqModes The modes to be checked: may be any combination of
      * {@link #CAP_MODE_CHARACTERS}, {@link #CAP_MODE_WORDS}, and
      * {@link #CAP_MODE_SENTENCES}.
-     * 
+     *
      * @return Returns the actual capitalization modes that can be in effect
      * at the current position, which is any combination of
      * {@link #CAP_MODE_CHARACTERS}, {@link #CAP_MODE_WORDS}, and
      * {@link #CAP_MODE_SENTENCES}.
      */
     public static int getCapsMode(CharSequence cs, int off, int reqModes) {
+        if (off < 0) {
+            return 0;
+        }
+
         int i;
         char c;
         int mode = 0;