diff options
| author | Rob Pike <r@golang.org> | 2012-02-09 08:58:40 +1100 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2012-02-09 08:58:40 +1100 |
| commit | c59dc485cdbd6e70ab5e8ed1b8e2d9a7e316dbe5 (patch) | |
| tree | 5bc27dc02e629a1a838b157b6f4bd10d8a1093bf /src/pkg | |
| parent | 3fce00d99e30d66f63f8e3cb85debc137329db0d (diff) | |
| download | go-c59dc485cdbd6e70ab5e8ed1b8e2d9a7e316dbe5.tar.xz | |
bytes.Buffer: return error in WriteTo if buffer is not drained
R=rsc
CC=golang-dev
https://golang.org/cl/5642065
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/bytes/buffer.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/pkg/bytes/buffer.go b/src/pkg/bytes/buffer.go index a95c2afd00..afdf220559 100644 --- a/src/pkg/bytes/buffer.go +++ b/src/pkg/bytes/buffer.go @@ -182,14 +182,21 @@ func makeSlice(n int) []byte { func (b *Buffer) WriteTo(w io.Writer) (n int64, err error) { b.lastRead = opInvalid if b.off < len(b.buf) { + nBytes := b.Len() m, e := w.Write(b.buf[b.off:]) + if m > nBytes { + panic("bytes.Buffer.WriteTo: invalid Write count") + } b.off += m n = int64(m) if e != nil { return n, e } - // otherwise all bytes were written, by definition of + // all bytes should have been written, by definition of // Write method in io.Writer + if m != nBytes { + return n, io.ErrShortWrite + } } // Buffer is now empty; reset. b.Truncate(0) |
