Skip to content

Commit f30783a

Browse files
committed
Perform conversion from string to []byte according to rule #6 at https://golang.org/pkg/unsafe/#Pointer
1 parent 25c1222 commit f30783a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

util_noappengine.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import (
77
"unsafe"
88
)
99

10-
func unsafeStrToBytes(s string) []byte {
10+
func unsafeStrToBytes(s string) (b []byte) {
1111
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
12-
bh := reflect.SliceHeader{
13-
Data: sh.Data,
14-
Len: sh.Len,
15-
Cap: sh.Len,
16-
}
17-
return *(*[]byte)(unsafe.Pointer(&bh))
12+
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
13+
bh.Data = sh.Data
14+
bh.Len = sh.Len
15+
bh.Cap = sh.Len
16+
return b
1817
}
1918

2019
func unsafeBytesToStr(z []byte) string {

0 commit comments

Comments
 (0)