Skip to content

Commit

Permalink
netbsd: Clarify type conversions are lossless.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Jun 2, 2024
1 parent 86b6f50 commit cbdfd69
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use core::{ffi::c_void, mem::MaybeUninit, ptr};

fn kern_arnd(buf: &mut [MaybeUninit<u8>]) -> libc::ssize_t {
static MIB: [libc::c_int; 2] = [libc::CTL_KERN, libc::KERN_ARND];
let mut len = buf.len();
let ret = unsafe {
#[allow(clippy::cast_possible_truncation)]
let mib_len = MIB.len() as libc::c_uint;

let mut len = core::cmp::min(buf.len(), libc::ssize_t::MAX.unsigned_abs());
let ret: libc::c_int = unsafe {
libc::sysctl(
MIB.as_ptr(),
MIB.len() as libc::c_uint,
mib_len,
buf.as_mut_ptr().cast::<c_void>(),
&mut len,
ptr::null(),
Expand All @@ -18,7 +21,10 @@ fn kern_arnd(buf: &mut [MaybeUninit<u8>]) -> libc::ssize_t {
if ret == -1 {
-1
} else {
len as libc::ssize_t
// We clamped the request to `ssize_t::MAX` bytes so this lossless.
#[allow(clippy::cast_possible_truncation)]
let len = len as libc::ssize_t;
len
}
}

Expand Down

0 comments on commit cbdfd69

Please sign in to comment.