Skip to content

Commit a89c325

Browse files
committed
Revert "Use from_bytes_with_nul for string check (#583)"
This reverts commit deec974.
1 parent 01ccaa2 commit a89c325

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cpufeatures/src/aarch64.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,18 @@ macro_rules! check {
121121
/// macOS helper function for calling `sysctlbyname`.
122122
#[cfg(target_os = "macos")]
123123
pub unsafe fn sysctlbyname(name: &[u8]) -> bool {
124-
let name = core::ffi::CStr::from_bytes_with_nul(name).unwrap();
124+
assert_eq!(
125+
name.last().cloned(),
126+
Some(0),
127+
"name is not NUL terminated: {:?}",
128+
name
129+
);
125130

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

129134
let rc = libc::sysctlbyname(
130-
name.as_ptr(),
135+
name.as_ptr() as *const i8,
131136
&mut value as *mut _ as *mut libc::c_void,
132137
&mut size,
133138
core::ptr::null_mut(),

0 commit comments

Comments
 (0)