mirror of
https://github.com/fluffle/goirc
synced 2025-05-12 18:44:50 +00:00
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...
This commit is contained in:
parent
38cd23891a
commit
0d4e83ea7f
1 changed files with 4 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue