Skip to content

Commit

Permalink
fix possible memory confusion in unsafe slice cast (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlauinger authored Jun 1, 2020
1 parent d08c5f3 commit fdbd1e5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/storage/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ func CopyIter(t reflect.Type, dst, src *Header, diter, siter Iterator) int {

func AsByteSlice(a *Header, t reflect.Type) []byte {
size := a.L * int(t.Size())
hdr := reflect.SliceHeader{
Data: uintptr(a.Ptr),
Len: size,
Cap: size,
}
return *(*[]byte)(unsafe.Pointer(&hdr))
b := make([]byte, 0)
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&b))
hdr.Data = uintptr(a.Ptr)
hdr.Cap = size
hdr.Len = size
return b
}

// Element gets the pointer of ith element
Expand Down

0 comments on commit fdbd1e5

Please sign in to comment.