From e695793e8464ce5795eb83fefd499dfd8aca19cb Mon Sep 17 00:00:00 2001 From: Tobias Nygren Date: Mon, 5 Aug 2024 02:22:57 +0200 Subject: [PATCH] collector/cpu_netbsd: fix integer sizes of hw.ncpu and kern.cp_time Signed-off-by: Tobias Nygren --- collector/cpu_netbsd.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/collector/cpu_netbsd.go b/collector/cpu_netbsd.go index 5a9e716c..1cc25590 100644 --- a/collector/cpu_netbsd.go +++ b/collector/cpu_netbsd.go @@ -183,7 +183,7 @@ func getCPUTimes() ([]cputime, error) { if err != nil { return nil, err } - ncpus := *(*int)(unsafe.Pointer(&ncpusb[0])) + ncpus := int(*(*uint32)(unsafe.Pointer(&ncpusb[0]))) if ncpus < 1 { return nil, errors.New("Invalid cpu number") @@ -195,10 +195,10 @@ func getCPUTimes() ([]cputime, error) { if err != nil { return nil, err } - for len(cpb) >= int(unsafe.Sizeof(int(0))) { - t := *(*int)(unsafe.Pointer(&cpb[0])) + for len(cpb) >= int(unsafe.Sizeof(uint64(0))) { + t := *(*uint64)(unsafe.Pointer(&cpb[0])) times = append(times, float64(t)/cpufreq) - cpb = cpb[unsafe.Sizeof(int(0)):] + cpb = cpb[unsafe.Sizeof(uint64(0)):] } }