summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.lang/String_overflow.java
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/testsuite/libjava.lang/String_overflow.java
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/testsuite/libjava.lang/String_overflow.java')
-rw-r--r--libjava/testsuite/libjava.lang/String_overflow.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.lang/String_overflow.java b/libjava/testsuite/libjava.lang/String_overflow.java
new file mode 100644
index 000000000..5a1a907c5
--- /dev/null
+++ b/libjava/testsuite/libjava.lang/String_overflow.java
@@ -0,0 +1,140 @@
+class String_overflow
+{
+ static void getChars()
+ {
+ String source = "abcdefg";
+ char[] dest = new char [3];
+
+ try
+ {
+ source.getChars (0, 5, // Source
+ dest, (1<<31) - 1);
+ Fail ("getChars", "Should not have succeeded");
+ }
+ catch (Throwable e)
+ {
+ ExpectArrayIndex ("getChars", e);
+ }
+ }
+
+ /* How do I stop a compiler warning causing a test to fail?
+ static void getBytes()
+ {
+ String source = "abcdefg";
+ byte[] dest = new byte[3];
+
+ try
+ {
+ source.getBytes (0, 5, dest, (1<<31) - 1);
+ Fail ("getBytes", "Should not have succeeded");
+ }
+ catch (Throwable e)
+ {
+ ExpectArrayIndex ("getBytes", e);
+ }
+ }
+ */
+
+ static void regionMatches()
+ {
+ if ("abcdefg".regionMatches (4, "abcdefg", 4, -1))
+ {
+ Fail ("regionMatches", "Should not return true");
+ }
+
+ try
+ {
+ if ("abcdefg".regionMatches (4, "abcdefg", 4, (1<<31)-1))
+ {
+ Fail ("regionMatches (2nd)", "Should not return true");
+ }
+ }
+ catch (Throwable e)
+ {
+ Fail ("regionMatches (2nd)", e);
+ }
+ }
+
+ static void regionMatchesCase()
+ {
+ if ("abcdefg".regionMatches (true, 4, "abcdefg", 4, -1))
+ {
+ Fail ("regionMatchesCase", "Should not return true");
+ }
+
+ try
+ {
+ if ("abcdefg".regionMatches (true, 4, "abcdefg", 4, (1<<31)-1))
+ {
+ Fail ("regionMatchesCase (2nd)", "Should not return true");
+ }
+ }
+ catch (Throwable e)
+ {
+ Fail ("regionMatchesCase (2nd)", e);
+ }
+ }
+
+ static void startsWith()
+ {
+ // We make the arg pretty big to try and cause a segfault.
+ String s = new String ("abcdef");
+ StringBuffer b = new StringBuffer (1000000);
+ b.setLength (1000000);
+ String arg = new String (b);
+
+ try
+ {
+ s.startsWith (arg, (1<<31) - 1000000);
+ }
+ catch (Throwable e)
+ {
+ Fail ("startsWith", e);
+ }
+ }
+
+ static void valueOf()
+ {
+ char[] array = new char[] {'a', 'b', 'c', 'd', 'e'};
+ try
+ {
+ String.valueOf (array, 4, (1<<31)-1);
+ Fail ("valueOf", "should not succeed");
+ }
+ catch (Throwable e)
+ {
+ ExpectArrayIndex ("valueOf", e);
+ }
+ }
+
+ public static void main (String[] args) throws Throwable
+ {
+ getChars();
+ // getBytes();
+ regionMatches();
+ regionMatchesCase();
+ startsWith();
+ valueOf();
+
+ if (tests_failed == 0)
+ System.out.println ("ok");
+ }
+
+ static void ExpectArrayIndex (String test, Throwable e)
+ {
+ if (e instanceof ArrayIndexOutOfBoundsException)
+ return;
+
+ Fail (test, e);
+ }
+
+ static void Fail (String test, Object problem)
+ {
+ ++tests_failed;
+ System.err.print (test);
+ System.err.print ('\t');
+ System.err.println (problem);
+ }
+
+ static int tests_failed;
+}