Skip to content

Commit

Permalink
Add more checks on host_processor_info
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 30, 2024
1 parent 43a1246 commit 851a1b2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/unix/apple/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ pub(crate) fn update_cpu_usage<F: FnOnce(Arc<CpuData>, *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);
}
Expand Down

0 comments on commit 851a1b2

Please sign in to comment.