mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes.Buffer: read of 0 bytes at EOF shouldn't be an EOF
This corner case arose doing an RPC with a empty-slice payload. Ouch. R=golang-dev, iant CC=golang-dev https://golang.org/cl/5505073
This commit is contained in:
parent
83d5402443
commit
6a88f1c4cb
2 changed files with 17 additions and 1 deletions
|
|
@ -373,3 +373,16 @@ func TestReadBytes(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Was a bug: used to give EOF reading empty slice at EOF.
|
||||
func TestReadEmptyAtEOF(t *testing.T) {
|
||||
b := new(Buffer)
|
||||
slice := make([]byte, 0)
|
||||
n, err := b.Read(slice)
|
||||
if err != nil {
|
||||
t.Errorf("read error: %v", err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Errorf("wrong count; got %d want 0", n)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue