Skip to content

Commit 2d8f35a

Browse files
author
Jason E. Aten, Ph.D.
committed
msgp.UnsafeString handles nil bytes
1 parent 38fb8b6 commit 2d8f35a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

msgp/unsafe.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !appengine
12
// +build !appengine
23

34
package msgp
@@ -24,6 +25,9 @@ const (
2425
// THIS IS EVIL CODE.
2526
// YOU HAVE BEEN WARNED.
2627
func UnsafeString(b []byte) string {
28+
if len(b) == 0 {
29+
return ""
30+
}
2731
return *(*string)(unsafe.Pointer(&reflect.StringHeader{Data: uintptr(unsafe.Pointer(&b[0])), Len: len(b)}))
2832
}
2933

0 commit comments

Comments
 (0)