From bdba65df16b9447f2cd340fbf96dc04e37bed04e Mon Sep 17 00:00:00 2001 From: ston1th Date: Tue, 1 Sep 2020 14:09:41 +0200 Subject: [PATCH] skip null bytes at the end of strings Signed-off-by: ston1th --- collector/sysctl_openbsd_amd64.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/collector/sysctl_openbsd_amd64.go b/collector/sysctl_openbsd_amd64.go index 56ae7346..3d805109 100644 --- a/collector/sysctl_openbsd_amd64.go +++ b/collector/sysctl_openbsd_amd64.go @@ -20,11 +20,15 @@ import ( ) func int8ToString(a []int8) string { - b := make([]byte, len(a)) + buf := make([]byte, len(a)) for i, v := range a { - b[i] = byte(v) + if byte(v) == 0 { + buf = buf[:i] + break + } + buf[i] = byte(v) } - return string(b) + return string(buf) } // unix._C_int