return "<nil>" when calling String() on a nil bytes.Buffer.
R=rsc
CC=go-dev
http://go/go-review/1016005
diff --git a/src/pkg/bytes/buffer.go b/src/pkg/bytes/buffer.go
index 7acddc4..6e5887c 100644
--- a/src/pkg/bytes/buffer.go
+++ b/src/pkg/bytes/buffer.go
@@ -42,8 +42,12 @@
}
// 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)]);
}