From a1758d83e298c9ee31848bcae07c2a35f6efd618 Mon Sep 17 00:00:00 2001 From: Alexei Zavjalov Date: Thu, 17 Apr 2014 01:55:43 +0700 Subject: String.IndexOf method handles negative start index value in incorrect way The standard implementation of String.IndexOf converts the negative value of the start index to 0 and searching will start from the beginning of the string. But current implementation may start searching from the incorrect memory offset, that can lead to sigsegv or return incorrect result. This patch adds the handler for cases when fromIndex is negative. Change-Id: I3ac86290712789559eaf5e46bef0006872395bfa Signed-off-by: Alexei Zavjalov --- test/082-inline-execute/src/Main.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/082-inline-execute') diff --git a/test/082-inline-execute/src/Main.java b/test/082-inline-execute/src/Main.java index 86a03ab..55ecf69 100644 --- a/test/082-inline-execute/src/Main.java +++ b/test/082-inline-execute/src/Main.java @@ -97,6 +97,7 @@ public class Main { } static int start; + private static int[] negIndex = { -100000 }; public static void test_String_indexOf() { String str0 = ""; String str1 = "/"; @@ -125,6 +126,7 @@ public class Main { Assert.assertEquals(str0.indexOf('a',0), -1); Assert.assertEquals(str0.indexOf('a',-1), -1); Assert.assertEquals(str1.indexOf('/',++start), -1); + Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1); Assert.assertEquals(str3.indexOf('a',0), 0); Assert.assertEquals(str3.indexOf('a',1), -1); Assert.assertEquals(str3.indexOf('a',1234), -1); -- cgit v1.1