[Mono-list] StreamReader.cs (ReadBuffer)
Nick Drochak
ndrochak@gol.com
Tue, 26 Mar 2002 00:43:22 +0900
Hi all.
While running the unit tests on Linux I found a bug in
StreamReader.ReadBuffer().
When the internal Stream is a MemoryStream and only has a few bytes in
it, rounding up to a multiple of 4096 caused an ArgumentException to be
thrown.
Below is a patch I came up with, but since Mike K. was just working on
this I didn't want to commit without his review.
Regards,
Nick
Index: StreamReader.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.IO/StreamReader.cs,v
retrieving revision 1.6
diff -u -r1.6 StreamReader.cs
--- StreamReader.cs 2002/03/24 13:40:26 1.6
+++ StreamReader.cs 2002/03/25 11:46:04
@@ -138,6 +138,11 @@
// Round up to block size
int size = RoundUpTo (count, 4096);
+
+ // But don't try to get more than there is
+ if (size > internalStream.Length)
+ size = (int)internalStream.Length;
+
byte[] bytes = new byte [size];
int cnt = internalStream.Read (bytes, 0, size);