]> Cypherpunks repositories - gostls13.git/commitdiff
io: fix nil Write bug in Pipe
authorRuss Cox <rsc@golang.org>
Fri, 29 Jan 2010 01:38:51 +0000 (17:38 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 29 Jan 2010 01:38:51 +0000 (17:38 -0800)
R=nigeltao_golang
CC=golang-dev
https://golang.org/cl/194132

src/pkg/io/pipe.go
src/pkg/io/pipe_test.go

index 8f821a9c66a57115412407bec0d5e54e3ffb7853..909989ae6adc8d3cf14afb7f9cc223947e319407 100644 (file)
@@ -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
index 793bed4596de1f5b9909b8eeaef9c71379ad91cd..b0ee0f20b364c56eb4fa0e6a3beeabeb5dbf4914 100644 (file)
@@ -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()
+}