From 6039a414aefe2168742b5ba694a309daa2bd76c6 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 28 Jan 2010 17:38:51 -0800 Subject: [PATCH] io: fix nil Write bug in Pipe R=nigeltao_golang CC=golang-dev https://golang.org/cl/194132 --- src/pkg/io/pipe.go | 2 +- src/pkg/io/pipe_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pkg/io/pipe.go b/src/pkg/io/pipe.go index 8f821a9c66..909989ae6a 100644 --- a/src/pkg/io/pipe.go +++ b/src/pkg/io/pipe.go @@ -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 diff --git a/src/pkg/io/pipe_test.go b/src/pkg/io/pipe_test.go index 793bed4596..b0ee0f20b3 100644 --- a/src/pkg/io/pipe_test.go +++ b/src/pkg/io/pipe_test.go @@ -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() +}