[Mono-list] Socket code.

Michal Moskal malekith@pld-linux.org
Sun, 22 Feb 2004 10:17:47 +0100


On Sat, Feb 21, 2004 at 04:31:00PM -0800, George Farris wrote:
> I have some socket code that looks something like this:
> 
> byte[] bytes = new byte[1448];
> do {
> 	len = sock.Read(bytes, 0, (int)1448);
> 	s = Encoding.ASCII.GetString(bytes);
> 	buf.Append(s.Substring(0,len));

Shouldn't it be:

 	s = Encoding.ASCII.GetString(bytes, 0, len);
 	buf.Append(s);

Passing some random junk (ergh.. does new byte[] clear memory?) to
encodoer doesn't seem good idea.

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: When in doubt, use brute force. -- Ken Thompson :: UL++++$ C++ E--- a?