From f9a5834e0eedaf00c5574a54f5b1f5f036f8ed24 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 7 Dec 2022 13:14:45 +0100 Subject: [PATCH] host: use unix.ByteSliceToString Use ByteSliceToString provided in golang.org/x/sys/unix to convert \0-terminated byte slices to strings. --- host/host_linux.go | 2 +- host/host_posix.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index 949babac4..5c07c6972 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -319,7 +319,7 @@ func KernelVersionWithContext(ctx context.Context) (version string, err error) { if err != nil { return "", err } - return string(utsname.Release[:bytes.IndexByte(utsname.Release[:], 0)]), nil + return unix.ByteSliceToString(utsname.Release[:]), nil } func getSlackwareVersion(contents []string) string { diff --git a/host/host_posix.go b/host/host_posix.go index 89e63781e..24529f19f 100644 --- a/host/host_posix.go +++ b/host/host_posix.go @@ -3,14 +3,13 @@ package host -import ( - "bytes" - - "golang.org/x/sys/unix" -) +import "golang.org/x/sys/unix" func KernelArch() (string, error) { var utsname unix.Utsname err := unix.Uname(&utsname) - return string(utsname.Machine[:bytes.IndexByte(utsname.Machine[:], 0)]), err + if err != nil { + return "", err + } + return unix.ByteSliceToString(utsname.Machine[:]), nil }