Hi, 

Below are some additional bugs I have encountered and proposed fixes.


1)


According to the JavaSpec, the method readLine() of the interface
java.io.DataInput is supposed to return "null" when end-of-file is reached
before even a single byte can be read. The class DataInputStream which
implements this interface has to do likewise. This is a single line change
of line 612 of ../java/io/DataInputStream.java.



--- DataInputStream.java        Thu Aug 04 
+++ DataInputStream.java        Thu Aug 31 16:59:08 2000
@@ -607,9 +607,9 @@
   for (;;)
     {
       int byte_read = in.read();
- 
+
       if (byte_read == -1)
-        return(sb.toString());
+               return null;
 
       char c = (char)byte_read;
 


==========================================================

2)


This pertains to the function java.io.BufferedReader.readLine(). 
"eol_pos" is computed by making a call to String.indexOf() and is the offset
at which the newline character occurs in the section of the String between
"pos" and "count", which is the unread region of the buffer. So when
creating a char array to return the new line in, "eol_pos" will be the size
of that array, not "eol_pos - pos".


Also, before System.arraycopy() to "newbuf" is called, "(bufpos > 0)" needs
to be checked as has been done in the other cases before.


Also, by the same reasoning as above, "bufpos" is incremented by "eol_pos"
bytes to account for the length of the new line that was just read out, and
not "eol_pos - pos".


And then again, "pos" too must be "incremented" by "eol_pos + (1 or 2)" as
the case may be since we are jumping ahead by as many bytes.


The diff is pasted below:


--- BufferedReader.java Aug 04 
+++ BufferedReader.java Aug 31 16:56:16 2000
@@ -565,19 +565,21 @@
        }
       else 
         {
-          // Copy the contents of the read buffer to our method buffer
-          char[] newbuf = new char[strbuf.length + (eol_pos - pos)];
-          System.arraycopy(strbuf, 0, newbuf, 0, bufpos);
+
+         // Copy the contents of the read buffer to our method buffer
+          char[] newbuf = new char[strbuf.length + (eol_pos)];
+         if (bufpos > 0)
+                 System.arraycopy(strbuf, 0, newbuf, 0, bufpos);
           strbuf = newbuf;
-          System.arraycopy(buf, pos, strbuf, bufpos, eol_pos - pos);
-          bufpos += (eol_pos - pos);
+          System.arraycopy(buf, pos, strbuf, bufpos, eol_pos);
+          bufpos += eol_pos;
  
           if (str.length() > (eol_pos + 1))
             {
               if (str.charAt(eol_pos) == '\n')
-                pos = eol_pos + 2;
+                pos += eol_pos + 2;
               else
-                pos = eol_pos + 1;
+                pos += eol_pos + 1;
             }
           else
             {




Reply via email to