summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-29 16:38:48 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-29 16:38:48 +0000
commit8dec8e5f66929061b9cab6ef349b3238287db701 (patch)
tree80c8fab2377be531c263136d07f8841302646c4f
parentb7edeb2322c878081a6542263dd698cfbd7b4136 (diff)
downloadppe42-gcc-8dec8e5f66929061b9cab6ef349b3238287db701.tar.gz
ppe42-gcc-8dec8e5f66929061b9cab6ef349b3238287db701.zip
* gnu/gcj/convert/natIconv.cc (write): Handle case where
output buffer is too small. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69927 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libjava/ChangeLog5
-rw-r--r--libjava/gnu/gcj/convert/natIconv.cc42
2 files changed, 33 insertions, 14 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 9c4177f9fd4..4af6516a693 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,8 @@
+2003-07-29 Tom Tromey <tromey@redhat.com>
+
+ * gnu/gcj/convert/natIconv.cc (write): Handle case where
+ output buffer is too small.
+
2003-07-28 Tom Tromey <tromey@redhat.com>
* java/lang/natString.cc (init(gnu.gcj.runtime.StringBuffer)):
diff --git a/libjava/gnu/gcj/convert/natIconv.cc b/libjava/gnu/gcj/convert/natIconv.cc
index 7b7ec64488e..d98e449677a 100644
--- a/libjava/gnu/gcj/convert/natIconv.cc
+++ b/libjava/gnu/gcj/convert/natIconv.cc
@@ -1,6 +1,6 @@
-// Input_iconv.java -- Java side of iconv() reader.
+// natIconv.cc -- Java side of iconv() reader.
-/* Copyright (C) 2000, 2001 Free Software Foundation
+/* Copyright (C) 2000, 2001, 2003 Free Software Foundation
This file is part of libgcj.
@@ -201,25 +201,39 @@ gnu::gcj::convert::Output_iconv::write (jcharArray inbuffer,
inbuf = (char *) temp_buffer;
}
- // If the conversion fails on the very first character, then we
- // assume that the character can't be represented in the output
- // encoding. There's nothing useful we can do here, so we simply
- // omit that character. Note that we can't check `errno' because
- // glibc 2.1.3 doesn't set it correctly. We could check it if we
- // really needed to, but we'd have to disable support for 2.1.3.
size_t loop_old_in = old_in;
while (1)
{
size_t r = iconv_adapter (iconv, (iconv_t) handle,
&inbuf, &inavail,
&outbuf, &outavail);
- if (r == (size_t) -1 && inavail == loop_old_in)
+ if (r == (size_t) -1)
{
- inavail -= 2;
- if (inavail == 0)
- break;
- loop_old_in -= 2;
- inbuf += 2;
+ if (errno == EINVAL)
+ {
+ // Incomplete byte sequence at the end of the input
+ // buffer. This shouldn't be able to happen here.
+ break;
+ }
+ else if (errno == E2BIG)
+ {
+ // Output buffer is too small.
+ break;
+ }
+ else if (errno == EILSEQ || inavail == loop_old_in)
+ {
+ // Untranslatable sequence. Since glibc 2.1.3 doesn't
+ // properly set errno, we also assume that this is what
+ // is happening if no conversions took place. (This can
+ // be a bogus assumption if in fact the output buffer is
+ // too small.) We skip the first character and try
+ // again.
+ inavail -= 2;
+ if (inavail == 0)
+ break;
+ loop_old_in -= 2;
+ inbuf += 2;
+ }
}
else
break;
OpenPOWER on IntegriCloud