From 0d4e83ea7fc97b3b3e222e342dd5fc4cdca57aaf Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Fri, 11 Nov 2011 08:34:55 +0000 Subject: [PATCH] Fix length bug in mockNetChan. Using the length of the provided buffer is dangerous after the first buffered read from it, as it'll be the length of the buffer size... --- client/mocknetconn_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/mocknetconn_test.go b/client/mocknetconn_test.go index b3908a8..2921313 100644 --- a/client/mocknetconn_test.go +++ b/client/mocknetconn_test.go @@ -103,13 +103,15 @@ func (m *mockNetConn) Read(b []byte) (int, os.Error) { if m.closed { return 0, os.EINVAL } + l := 0 select { case s := <-m.in: + l = len(s) copy(b, s) case <-m.rc: return 0, os.EOF } - return len(b), nil + return l, nil } func (m *mockNetConn) Write(s []byte) (int, os.Error) { @@ -119,7 +121,7 @@ func (m *mockNetConn) Write(s []byte) (int, os.Error) { b := make([]byte, len(s)) copy(b, s) m.out <- b - return len(b), nil + return len(s), nil } func (m *mockNetConn) Close() os.Error {