Skip to content

Commit c208f03

Browse files
committed
pkg/devicemapper: fix invalid usage of reflect.SliceHeader
The current usage of reflect.SliceHeader violates rule 6th of unsafe.Pointer conversion. In short, reflect.SliceHeader could not be used as plain struct. See https://golang.org/pkg/unsafe/#Pointer Signed-off-by: Cuong Manh Le <[email protected]>
1 parent 7bb1944 commit c208f03

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

pkg/devicemapper/devmapper_wrapper.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ func dmTaskGetDepsFct(task *cdmTask) *Deps {
150150
}
151151

152152
// golang issue: https://github.com/golang/go/issues/11925
153-
hdr := reflect.SliceHeader{
154-
Data: uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps))),
155-
Len: int(Cdeps.count),
156-
Cap: int(Cdeps.count),
157-
}
158-
devices := *(*[]C.uint64_t)(unsafe.Pointer(&hdr))
153+
var devices []C.uint64_t
154+
devicesHdr := (*reflect.SliceHeader)(unsafe.Pointer(&devices))
155+
devicesHdr.Data = uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(Cdeps)) + unsafe.Sizeof(*Cdeps)))
156+
devicesHdr.Len = int(Cdeps.count)
157+
devicesHdr.Cap = int(Cdeps.count)
159158

160159
deps := &Deps{
161160
Count: uint32(Cdeps.count),

0 commit comments

Comments
 (0)