PR 3426 fix

Tom Tromey tromey@redhat.com
Thu Aug 2 10:17:00 GMT 2001


>>>>> "Tony" == Tony Kimball <alk@pobox.com> writes:

Tom>  I went and read the libc docs on iconv.  Now I think the right code
Tom>  should look like this:
Tom>        if (errno == EINVAL || errno == E2BIG)
Tom>  	return 0;

Tony> It's not true that 0 chars were converted on E2BIG.  It is true
Tony> that old_outlength - outlength / sizeof(jchar) (or whatever
Tony> those vars were called) chars were converted on E2BIG.

You're right.  I misread the docs.
I think this is also true for EINVAL, right?  We might have converted
a bunch of the input, but then encountered an incomplete sequence at
the end.  So it seems that in both these cases we must fall through.

What do you think of the appended patch?

Tom>  Hmm... a comment later on says that glibc 2.1.3 doesn't correctly set 
Tom>  errno.  Not sure what to do about that.  

Tony> Is there an imperative to accomodate the bugs of old versions of
Tony> glibc?

Well, this glibc is what is in use on Red Hat Linux 6.2.  This is
still widely used.  (I use it :-)

However, I agree we should be forward-looking.
I'm inclined to go with the appended.

Tom

Index: gnu/gcj/convert/natIconv.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/convert/natIconv.cc,v
retrieving revision 1.10
diff -u -r1.10 natIconv.cc
--- gnu/gcj/convert/natIconv.cc 2001/07/30 20:24:18 1.10
+++ gnu/gcj/convert/natIconv.cc 2001/08/02 17:12:41
@@ -90,10 +90,13 @@
 
   if (r == (size_t) -1)
     {
-      // Incomplete character.
-      if (errno == EINVAL || errno == E2BIG)
-	return 0;
-      throw new java::io::CharConversionException ();
+      // If we see EINVAL then there is an incomplete sequence at the
+      // end of the input buffer.  If we see E2BIG then we ran out of
+      // space in the output buffer.  However, in both these cases
+      // some conversion might have taken place.  So we fall through
+      // to the normal case.
+      if (errno != EINVAL && errno != E2BIG)
+	throw new java::io::CharConversionException ();
     }
 
   if (iconv_byte_swap)



More information about the Java-patches mailing list