[Mono-list] Mono 0.23 Bug in the method System.IO.StringReader.Read

Igor Nosyryev nosyryev@attbi.com
Sat, 19 Apr 2003 16:11:08 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0011_01C3068E.49B0EBC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Class: System.IO.StringReader

Method: public override int Read( char[] buffer, int index, int count )

Problem:
If there are no more characters (end-of-stream) call to this method =
generates the exception. But it should just return 0.

CVS code:

public override int Read( char[] buffer, int index, int count ) {

			CheckObjectDisposedException ();

			if( buffer =3D=3D null ) {
				throw new ArgumentNullException();
			} else if( buffer.Length - index < count ) {
				throw new ArgumentException();
			} else if( index < 0 || count < 0 ) {
				throw new ArgumentOutOfRangeException();
			}

			int charsToRead;

			if( nextChar + count > sourceLength ) {
				charsToRead =3D sourceLength - nextChar;
			} else {
				charsToRead =3D count;
			}

			Array.Copy(sourceChars, nextChar, buffer, index, charsToRead );

			nextChar +=3D count;

			return charsToRead;
		}

Make change:

public override int Read( char[] buffer, int index, int count ) {

			CheckObjectDisposedException ();

			if( buffer =3D=3D null ) {
				throw new ArgumentNullException();
			} else if( buffer.Length - index < count ) {
				throw new ArgumentException();
			} else if( index < 0 || count < 0 ) {
				throw new ArgumentOutOfRangeException();
			}

			int charsToRead;

			if( nextChar + count > sourceLength ) {
				charsToRead =3D sourceLength - nextChar;
			} else {
				charsToRead =3D count;
			}
if(charsToRead < 1) return 0;

Array.Copy(sourceChars, nextChar, buffer, index, charsToRead );

			nextChar +=3D count;

			return charsToRead;
		}

-----------------------------------------------
Igor Nosyryev
E-mail: nosyryev@attbi.com

------=_NextPart_000_0011_01C3068E.49B0EBC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DVerdana size=3D2>Class: =
System.IO.StringReader</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Method: public override int Read( =
char[] buffer,=20
int index, int count )</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Problem:</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>If there are no more characters =
(end-of-stream)=20
call to this method generates the exception. But it should just return=20
0.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>CVS code:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>public override int Read( =
char[] buffer,=20
int index, int count ) {<BR><BR>			CheckObjectDisposedException=20
();<BR><BR>			if( buffer =3D=3D null ) {<BR>				throw new=20
ArgumentNullException();<BR>			} else if( buffer.Length - index &lt; =
count )=20
{<BR>				throw new ArgumentException();<BR>			} else if( index &lt; 0 || =
count=20
&lt; 0 ) {<BR>				throw new ArgumentOutOfRangeException();<BR>			=
}<BR><BR>			int=20
charsToRead;<BR><BR>			if( nextChar + count &gt; sourceLength )=20
{<BR>				charsToRead =3D sourceLength - nextChar;<BR>			} else=20
{<BR>				charsToRead =3D count;<BR>			}<BR><BR>			=
Array.Copy(sourceChars,=20
nextChar, buffer, index, charsToRead );<BR><BR>			nextChar +=3D=20
count;<BR><BR>			return charsToRead;<BR>		}<BR></FONT><BR><FONT =
face=3DVerdana=20
size=3D2>Make change:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>public override int Read( =
char[] buffer,=20
int index, int count ) {<BR><BR>			CheckObjectDisposedException=20
();<BR><BR>			if( buffer =3D=3D null ) {<BR>				throw new=20
ArgumentNullException();<BR>			} else if( buffer.Length - index &lt; =
count )=20
{<BR>				throw new ArgumentException();<BR>			} else if( index &lt; 0 || =
count=20
&lt; 0 ) {<BR>				throw new ArgumentOutOfRangeException();<BR>			=
}<BR><BR>			int=20
charsToRead;<BR><BR>			if( nextChar + count &gt; sourceLength )=20
{<BR>				charsToRead =3D sourceLength - nextChar;<BR>			} else=20
{<BR>				charsToRead =3D count;<BR>			}<BR></FONT><FONT face=3D"Courier =
New"=20
color=3D#ff0000 size=3D2>if(charsToRead &lt; 1) return =
0;</FONT></DIV><FONT=20
face=3D"Courier New" size=3D2>
<DIV><FONT face=3DArial></FONT><BR>Array.Copy(sourceChars, nextChar, =
buffer,=20
index, charsToRead );<BR><BR>			nextChar +=3D count;<BR><BR>			return=20
charsToRead;<BR>		}<BR></DIV>
<DIV><FONT=20
face=3DArial>-----------------------------------------------</FONT><BR><F=
ONT=20
face=3DVerdana>Igor Nosyryev</FONT></DIV>
<DIV><FONT face=3DVerdana>E-mail: </FONT><A =
href=3D"mailto:nosyryev@attbi.com"><FONT=20
face=3DVerdana>nosyryev@attbi.com</FONT></A></DIV>
<DIV><FONT face=3DArial></FONT>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_0011_01C3068E.49B0EBC0--