summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaney <daney@138bc75d-0d04-0410-961f-82ee72b054a4>2008-05-21 03:49:03 +0000
committerdaney <daney@138bc75d-0d04-0410-961f-82ee72b054a4>2008-05-21 03:49:03 +0000
commitecf4434945c54a6770abffbc3c61e7bdf16350fe (patch)
treee6e58a2d11b2eb0a13884ca5f7d7d4db1b0158ca
parentc0d85f84d6242423d5cd1c8ecec174c29cc394a0 (diff)
downloadgcc-ecf4434945c54a6770abffbc3c61e7bdf16350fe.tar.gz
2008-05-20 David Daney <ddaney@avtrex.com>
PR libgcj/36252 * java/lang/natString.ccn: Add #include <java/io/CharConversionException.h>. (init (byte[], int, int, String)): Catch and ignore CharConversionException. Break out of conversion loop on incomplete input. * testsuite/libjava.lang/PR36252.java: New test. * testsuite/libjava.lang/PR36252.out: New file, its expected output. * testsuite/libjava.lang/PR36252.jar: New file, its pre-compiled jar file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135705 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/ChangeLog13
-rw-r--r--libjava/java/lang/natString.cc25
-rw-r--r--libjava/testsuite/libjava.lang/PR36252.jarbin0 -> 959 bytes
-rw-r--r--libjava/testsuite/libjava.lang/PR36252.java16
-rw-r--r--libjava/testsuite/libjava.lang/PR36252.out1
5 files changed, 53 insertions, 2 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index c639181c878..e8cd46e8947 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,16 @@
+2008-05-20 David Daney <ddaney@avtrex.com>
+
+ PR libgcj/36252
+ * java/lang/natString.ccn: Add
+ #include <java/io/CharConversionException.h>.
+ (init (byte[], int, int, String)): Catch and ignore
+ CharConversionException. Break out of conversion loop
+ on incomplete input.
+ * testsuite/libjava.lang/PR36252.java: New test.
+ * testsuite/libjava.lang/PR36252.out: New file, its expected output.
+ * testsuite/libjava.lang/PR36252.jar: New file, its pre-compiled
+ jar file.
+
2008-04-19 Tom Tromey <tromey@redhat.com>
PR libgcj/35979:
diff --git a/libjava/java/lang/natString.cc b/libjava/java/lang/natString.cc
index f177c23ccc4..75006a7c9a7 100644
--- a/libjava/java/lang/natString.cc
+++ b/libjava/java/lang/natString.cc
@@ -1,6 +1,7 @@
// natString.cc - Implementation of java.lang.String native methods.
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008 Free Software Foundation
This file is part of libgcj.
@@ -23,6 +24,7 @@ details. */
#include <java/lang/NullPointerException.h>
#include <java/lang/StringBuffer.h>
#include <java/io/ByteArrayOutputStream.h>
+#include <java/io/CharConversionException.h>
#include <java/io/OutputStreamWriter.h>
#include <java/io/ByteArrayInputStream.h>
#include <java/io/InputStreamReader.h>
@@ -493,9 +495,28 @@ java::lang::String::init (jbyteArray bytes, jint offset, jint count,
converter->setInput(bytes, offset, offset+count);
while (converter->inpos < converter->inlength)
{
- int done = converter->read(array, outpos, avail);
+ int done;
+ try
+ {
+ done = converter->read(array, outpos, avail);
+ }
+ catch (::java::io::CharConversionException *e)
+ {
+ // Ignore it and silently throw away the offending data.
+ break;
+ }
if (done == 0)
{
+ // done is zero if either there is no space available in the
+ // output *or* the input is incomplete. We assume that if
+ // there are 20 characters available in the output, the
+ // input must be incomplete and there is no more work to do.
+ // This means we may skip several bytes of input, but that
+ // is OK as the behavior is explicitly unspecified in this
+ // case.
+ if (avail - outpos > 20)
+ break;
+
jint new_size = 2 * (outpos + avail);
jcharArray new_array = JvNewCharArray (new_size);
memcpy (elements (new_array), elements (array),
diff --git a/libjava/testsuite/libjava.lang/PR36252.jar b/libjava/testsuite/libjava.lang/PR36252.jar
new file mode 100644
index 00000000000..2c0d2c0e906
--- /dev/null
+++ b/libjava/testsuite/libjava.lang/PR36252.jar
Binary files differ
diff --git a/libjava/testsuite/libjava.lang/PR36252.java b/libjava/testsuite/libjava.lang/PR36252.java
new file mode 100644
index 00000000000..4f39a678b1a
--- /dev/null
+++ b/libjava/testsuite/libjava.lang/PR36252.java
@@ -0,0 +1,16 @@
+import java.io.UnsupportedEncodingException;
+
+public class PR36252
+{
+ public static void main(String[] args)
+ {
+ try {
+ byte[] txt = new byte[] {-55, 87, -55, -42, -55, -20};
+ // This new String(...) should not throw an OutOfMemoryError.
+ String s = new String(txt, 0, 6, "MS932");
+ } catch (UnsupportedEncodingException e) {
+ // Silently ignore.
+ }
+ System.out.println("ok");
+ }
+}
diff --git a/libjava/testsuite/libjava.lang/PR36252.out b/libjava/testsuite/libjava.lang/PR36252.out
new file mode 100644
index 00000000000..9766475a418
--- /dev/null
+++ b/libjava/testsuite/libjava.lang/PR36252.out
@@ -0,0 +1 @@
+ok