From 851a1b2e59fdcd61749e85cfeda52945c8881403 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 30 Jan 2024 11:24:45 +0100 Subject: [PATCH] Add more checks on `host_processor_info` --- src/unix/apple/cpu.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/unix/apple/cpu.rs b/src/unix/apple/cpu.rs index 5ccb0bf90..5d20dc211 100644 --- a/src/unix/apple/cpu.rs +++ b/src/unix/apple/cpu.rs @@ -263,10 +263,14 @@ pub(crate) fn update_cpu_usage, *mut i32) -> (f32, usize) &mut cpu_info as *mut *mut i32, &mut num_cpu_info as *mut u32, ) == libc::KERN_SUCCESS + && num_cpu_info > 0 + && !cpu_info.is_null() { let (total_percentage, len) = f(Arc::new(CpuData::new(cpu_info, num_cpu_info)), cpu_info); total_cpu_usage = total_percentage / len as f32; + } else { + sysinfo_debug!("host_processor_info failed, not updating CPU ticks usage..."); } global_cpu.inner.set_cpu_usage(total_cpu_usage); }