Skip to content

Commit

Permalink
Use from_bytes_with_nul for string check (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Aug 20, 2021
1 parent dde4dad commit deec974
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cpufeatures/src/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,13 @@ macro_rules! check {
/// macOS helper function for calling `sysctlbyname`.
#[cfg(target_os = "macos")]
pub unsafe fn sysctlbyname(name: &[u8]) -> bool {
assert_eq!(
name.last().cloned(),
Some(0),
"name is not NUL terminated: {:?}",
name
);
let name = core::ffi::CStr::from_bytes_with_nul(name).unwrap();

let mut value: u32 = 0;
let mut size = core::mem::size_of::<u32>();

let rc = libc::sysctlbyname(
name.as_ptr() as *const i8,
name.as_ptr(),
&mut value as *mut _ as *mut libc::c_void,
&mut size,
core::ptr::null_mut(),
Expand Down

0 comments on commit deec974

Please sign in to comment.