Closed
Description
See golang/go#53003
As stated in Proposal:
- converting []byte to string
- converting string to []byte
- grabbing the Data pointer field for ffi or some other niche use
- converting a slice of one type to a slice of another type
The first use case can also commonly be seen as *(*string)(unsafe.Pointer(&mySlice)), which is never actually officially documented anywhere as something that can be relied upon. Under the hood, the shape of a string is less than a slice, so this seems valid per unsafe rule (1), but this is all relying on undocumented behavior. The second use case is commonly seen as ([]byte)(unsafe.Pointer(&string)), which is by-default broken because the Cap field can be past the end of a page boundary (example here, in widely used code) -- this violates unsafe rule (1).
:)
Metadata
Metadata
Assignees
Labels
No labels