aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ipc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-02-09 12:26:03 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-02-09 14:09:19 +0200
commit553630e1a968aebffd0eafb360723287621efdbf (patch)
tree2cfa769cfdfd3379a388e8de51d36e3489164dfe /pkg/ipc
parenteb99c7d3da996d1a1dabd18aea6781262648dadb (diff)
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.
Diffstat (limited to 'pkg/ipc')
-rw-r--r--pkg/ipc/ipc.go17
1 files changed, 13 insertions, 4 deletions
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
}