diff options
author | Rob Pike <r@golang.org> | 2009-10-31 13:28:22 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2009-10-31 13:28:22 -0700 |
commit | 7d570bcf1c1e066bd63c9aa1d0dafdd1b71a9f08 (patch) | |
tree | 993c99308674b47072756d4c6aab926db1142984 /src/pkg/bytes/buffer.go | |
parent | 5746b0f746ee412890c535f60c14912e33f9f6db (diff) | |
download | golang-7d570bcf1c1e066bd63c9aa1d0dafdd1b71a9f08.tar.gz |
return "<nil>" when calling String() on a nil bytes.Buffer.
R=rsc
CC=go-dev
http://go/go-review/1016005
Diffstat (limited to 'src/pkg/bytes/buffer.go')
-rw-r--r-- | src/pkg/bytes/buffer.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/pkg/bytes/buffer.go b/src/pkg/bytes/buffer.go index 7acddc4bc..6e5887cb0 100644 --- a/src/pkg/bytes/buffer.go +++ b/src/pkg/bytes/buffer.go @@ -42,8 +42,12 @@ func (b *Buffer) Bytes() []byte { } // String returns the contents of the unread portion of the buffer -// as a string. +// as a string. If the Buffer is a nil pointer, it returns "<nil>". func (b *Buffer) String() string { + if b == nil { + // Special case, useful in debugging. + return "<nil>" + } return string(b.buf[b.off : len(b.buf)]); } |