diff --git a/lib/bytesutil/bytesutil.go b/lib/bytesutil/bytesutil.go index 67c67636b..969e63e83 100644 --- a/lib/bytesutil/bytesutil.go +++ b/lib/bytesutil/bytesutil.go @@ -64,12 +64,12 @@ func roundToNearestPow2(n int) int { // // The returned string is valid only until b is reachable and unmodified. func ToUnsafeString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) } // ToUnsafeBytes converts s to a byte slice without memory allocations. // // The returned byte slice is valid only until s is reachable and unmodified. -func ToUnsafeBytes(s string) (b []byte) { +func ToUnsafeBytes(s string) []byte { return unsafe.Slice(unsafe.StringData(s), len(s)) }