From 4c477510c32ac0895e20ee0a9b4e1752edfacdc9 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Tue, 15 Jun 2021 21:03:47 +0800 Subject: [PATCH] Chore: use unix.ByteSliceToString transform cstring --- component/process/process_darwin.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/component/process/process_darwin.go b/component/process/process_darwin.go index 5157b209..7e4baf74 100644 --- a/component/process/process_darwin.go +++ b/component/process/process_darwin.go @@ -1,12 +1,13 @@ package process import ( - "bytes" "encoding/binary" "net" "path/filepath" "syscall" "unsafe" + + "golang.org/x/sys/unix" ) const ( @@ -94,12 +95,8 @@ func getExecPathFromPID(pid uint32) (string, error) { if errno != 0 { return "", errno } - firstZero := bytes.IndexByte(buf, 0) - if firstZero <= 0 { - return "", nil - } - return filepath.Base(string(buf[:firstZero])), nil + return filepath.Base(unix.ByteSliceToString(buf)), nil } func readNativeUint32(b []byte) uint32 {