aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ipc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-04-26 12:37:59 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-04-26 11:42:18 +0000
commit968cb91346aa85e5ddbc7080d80cfe84975329f5 (patch)
treeb2aa9b05b7dd2ef2564fb28cef9636469fff21d6 /pkg/ipc
parent45832ea5223b57cba6e12d8390e82b0148780763 (diff)
pkg/ipc: remove use of reflect.SliceHeader
Linter now complains: Error: SA1019: reflect.SliceHeader has been deprecated since Go 1.21 and an alternative has been available since Go 1.17: Use unsafe.Slice or unsafe.SliceData instead.
Diffstat (limited to 'pkg/ipc')
-rw-r--r--pkg/ipc/ipc.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go
index 16840f6a2..daebc257d 100644
--- a/pkg/ipc/ipc.go
+++ b/pkg/ipc/ipc.go
@@ -9,7 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
- "reflect"
+ "slices"
"strings"
"sync"
"time"
@@ -479,20 +479,15 @@ func readUint32Array(outp *[]byte, size uint32) ([]uint32, bool) {
return nil, true
}
out := *outp
- if int(size)*4 > len(out) {
+ dataSize := int(size * 4)
+ if dataSize > len(out) {
return nil, false
}
// "Convert" the data to uint32.
- var res []uint32
- hdr := (*reflect.SliceHeader)((unsafe.Pointer(&res)))
- hdr.Data = uintptr(unsafe.Pointer(&out[0]))
- hdr.Len = int(size)
- hdr.Cap = int(size)
- *outp = out[size*4:]
- // Now duplicate the resulting array.
- dupRes := make([]uint32, size)
- copy(dupRes, res)
- return dupRes, true
+ res := unsafe.Slice((*uint32)(unsafe.Pointer(&out[0])), size)
+ *outp = out[dataSize:]
+ // Detach the resulting array from the original data.
+ return slices.Clone(res), true
}
type command struct {