File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,10 @@ func (p *pipe) Read(d []byte) (n int, err error) {
77
77
}
78
78
}
79
79
80
- var errClosedPipeWrite = errors .New ("write on closed buffer" )
80
+ var (
81
+ errClosedPipeWrite = errors .New ("write on closed buffer" )
82
+ errUninitializedPipeWrite = errors .New ("write on uninitialized buffer" )
83
+ )
81
84
82
85
// Write copies bytes from p into the buffer and wakes a reader.
83
86
// It is an error to write more data than the buffer can hold.
@@ -91,6 +94,12 @@ func (p *pipe) Write(d []byte) (n int, err error) {
91
94
if p .err != nil || p .breakErr != nil {
92
95
return 0 , errClosedPipeWrite
93
96
}
97
+ // pipe.setBuffer is never invoked, leaving the buffer uninitialized.
98
+ // We shouldn't try to write to an uninitialized pipe,
99
+ // but returning an error is better than panicking.
100
+ if p .b == nil {
101
+ return 0 , errUninitializedPipeWrite
102
+ }
94
103
return p .b .Write (d )
95
104
}
96
105
You can’t perform that action at this time.
0 commit comments