summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/io/bytebuffer.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/io/bytebuffer.go b/src/lib/io/bytebuffer.go
index 903536717..8af8a09aa 100644
--- a/src/lib/io/bytebuffer.go
+++ b/src/lib/io/bytebuffer.go
@@ -75,7 +75,15 @@ func (b *ByteBuffer) Len() int {
return b.len
}
+// If the buffer is empty, Data() should still give a valid array.
+// Use this variable as a surrogate. It's immutable (can't be
+// grown, can't store any data) so it's safe to share.
+var EmptyByteArray = new([]byte, 0)
+
func (b *ByteBuffer) Data() *[]byte {
+ if b.buf == nil {
+ return EmptyByteArray
+ }
return b.buf[b.off:b.len]
}