Fix possible misuse of reflect.StringHeader
This commit is contained in:
parent
1fc6093383
commit
5cb47021ac
|
@ -21,8 +21,10 @@ func bytesAsString(b []byte) string {
|
|||
if len(b) == 0 {
|
||||
return ""
|
||||
}
|
||||
return *(*string)(unsafe.Pointer(&reflect.StringHeader{
|
||||
uintptr(unsafe.Pointer(&b[0])),
|
||||
len(b),
|
||||
}))
|
||||
// See https://github.com/golang/go/issues/40701.
|
||||
var s string
|
||||
hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||
hdr.Data = uintptr(unsafe.Pointer(&b[0]))
|
||||
hdr.Len = len(b)
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue