From 553630e1a968aebffd0eafb360723287621efdbf Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 9 Feb 2020 12:26:03 +0200 Subject: pkg/ipc: remove use of unsafe Unsafe is, well, unsafe. Plus it fails under the new checkptr mode in go1.14. Remove some uses of unsafe. --- pkg/ipc/ipc.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'pkg') diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index a238d2ba4..9ee7843d3 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -4,12 +4,14 @@ package ipc import ( + "encoding/binary" "fmt" "io" "io/ioutil" "os" "os/exec" "path/filepath" + "reflect" "strings" "sync/atomic" "time" @@ -437,7 +439,7 @@ func readUint32(outp *[]byte) (uint32, bool) { if len(out) < 4 { return 0, false } - v := *(*uint32)(unsafe.Pointer(&out[0])) + v := binary.LittleEndian.Uint32(out) *outp = out[4:] return v, true } @@ -447,18 +449,25 @@ func readUint64(outp *[]byte) (uint64, bool) { if len(out) < 8 { return 0, false } - v := *(*uint64)(unsafe.Pointer(&out[0])) + v := binary.LittleEndian.Uint64(out) *outp = out[8:] return v, true } func readUint32Array(outp *[]byte, size uint32) ([]uint32, bool) { + if size == 0 { + return nil, true + } out := *outp if int(size)*4 > len(out) { return nil, false } - arr := ((*[1 << 28]uint32)(unsafe.Pointer(&out[0]))) - res := arr[:size:size] + hdr := reflect.SliceHeader{ + Data: uintptr(unsafe.Pointer(&out[0])), + Len: int(size), + Cap: int(size), + } + res := *(*[]uint32)(unsafe.Pointer(&hdr)) *outp = out[size*4:] return res, true } -- cgit mrf-deployment