summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2003-08-16 13:16:53 +0000
committerMark Wielaard <mark@klomp.org>2003-08-16 13:16:53 +0000
commit5a1dc943e4e26a56467ff09339d6eb0131a3c996 (patch)
tree263d7d032c365fadda19273fb5b873d25a79bffe
parente6c9eea260df6c56fb45258172472c3ae36c2000 (diff)
downloadclasspath-5a1dc943e4e26a56467ff09339d6eb0131a3c996.tar.gz
Reported by Patrik Reali
* gnu/java/io/decode/DecoderUTF8.java (charsInByteArray): Take offset into account. (convertToChars): Take buf_offset into account. (read): Take offset into account. Break loop early when in.avaiable() <= 0.
-rw-r--r--ChangeLog9
-rw-r--r--gnu/java/io/decode/DecoderUTF8.java15
2 files changed, 20 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index fe7bf1098..d95fa5c14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2003-08-16 Mark Wielaard <mark@klomp.org>
+ Reported by Patrik Reali
+ * gnu/java/io/decode/DecoderUTF8.java (charsInByteArray): Take offset
+ into account.
+ (convertToChars): Take buf_offset into account.
+ (read): Take offset into account. Break loop early when
+ in.avaiable() <= 0.
+
+2003-08-16 Mark Wielaard <mark@klomp.org>
+
Reported by Julian Dolby
* java/lang/Package.java (getPackage): Use currentClassLoader() not
VMSecurityManager.getClassContext()[1].getClassLoader().
diff --git a/gnu/java/io/decode/DecoderUTF8.java b/gnu/java/io/decode/DecoderUTF8.java
index 8b4c95b7c..5e4e60616 100644
--- a/gnu/java/io/decode/DecoderUTF8.java
+++ b/gnu/java/io/decode/DecoderUTF8.java
@@ -1,5 +1,5 @@
/* DecoderUTF8.java -- Decoder for the UTF-8 character encoding.
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -88,7 +88,7 @@ charsInByteArray(byte[] buf, int offset, int len) throws CharConversionException
int num_chars = 0;
// Scan the buffer with minimal validation checks
- for (int i = offset; i < len; i++)
+ for (int i = offset; i < offset + len; i++)
{
// Three byte encoding case.
if ((buf[i] & 0xE0) == 0xE0) // 224
@@ -134,7 +134,7 @@ convertToChars(byte[] buf, int buf_offset, int len, char cbuf[],
int val;
// Scan the buffer with full validation checks
- for (int i = buf_offset; i < len; i++)
+ for (int i = buf_offset; i < buf_offset + len; i++)
{
// Three byte encoding case.
if ((buf[i] & 0xE0) == 0xE0) // 224
@@ -197,7 +197,7 @@ read(char[] cbuf, int offset, int len) throws IOException
// Note that this method of reading a single byte at a time is
// inefficient and should probably be replaced
- for (int i = offset; i < len; i++)
+ for (int i = offset; i < offset + len; i++)
{
// Read a byte
int b = in.read();
@@ -249,6 +249,13 @@ read(char[] cbuf, int offset, int len) throws IOException
}
cbuf[i] = (char)val;
+
+ // if no more bytes available, terminate loop early, instead of
+ // blocking in in.read().
+ // Do not test this in the for condition: it must call in.read() at
+ // least once (and thus block if "in" is empty).
+ if (in.available() <= 0)
+ return (1 + i - offset);
}
return(len);