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 <cuong.manhle.vn@gmail.com>
| ... | ... |
@@ -150,12 +150,11 @@ func dmTaskGetDepsFct(task *cdmTask) *Deps {
|
| 150 | 150 |
} |
| 151 | 151 |
|
| 152 | 152 |
// 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) |
|
| 159 | 158 |
|
| 160 | 159 |
deps := &Deps{
|
| 161 | 160 |
Count: uint32(Cdeps.count), |