Skip to content

Commit

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

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

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

0 comments on commit a5b0647

Please sign in to comment.