mirror of
https://github.com/golang/go
synced 2024-11-21 20:44:39 -07:00
io: fix nil Write bug in Pipe
R=nigeltao_golang CC=golang-dev https://golang.org/cl/194132
This commit is contained in:
parent
d7a5ccf36e
commit
6039a414ae
@ -39,7 +39,7 @@ func (p *pipe) Read(data []byte) (n int, err os.Error) {
|
||||
if !p.wclosed {
|
||||
p.wpend = <-p.cr
|
||||
}
|
||||
if p.wpend == nil {
|
||||
if p.wclosed {
|
||||
return 0, p.werr
|
||||
}
|
||||
p.wtot = 0
|
||||
|
@ -236,3 +236,25 @@ func TestPipeWriteClose(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteEmpty(t *testing.T) {
|
||||
r, w := Pipe()
|
||||
go func() {
|
||||
w.Write([]byte{})
|
||||
w.Close()
|
||||
}()
|
||||
var b [2]byte
|
||||
ReadFull(r, b[0:2])
|
||||
r.Close()
|
||||
}
|
||||
|
||||
func TestWriteNil(t *testing.T) {
|
||||
r, w := Pipe()
|
||||
go func() {
|
||||
w.Write(nil)
|
||||
w.Close()
|
||||
}()
|
||||
var b [2]byte
|
||||
ReadFull(r, b[0:2])
|
||||
r.Close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user