return "<nil>" when calling String() on a nil bytes.Buffer.

R=rsc
CC=go-dev
http://go/go-review/1016005
This commit is contained in:
Rob Pike 2009-10-31 13:28:22 -07:00
parent aa0c811317
commit 63e668d2ad
2 changed files with 13 additions and 1 deletions

View file

@ -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)]);
}