File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1
1
//! Implementation for NetBSD
2
2
use crate :: { lazy:: LazyPtr , util_libc:: sys_fill_exact, Error } ;
3
- use core:: { ffi:: c_void, mem:: MaybeUninit , ptr} ;
3
+ use core:: { cmp , ffi:: c_void, mem:: MaybeUninit , ptr} ;
4
4
5
5
fn kern_arnd ( buf : & mut [ MaybeUninit < u8 > ] ) -> libc:: ssize_t {
6
6
static MIB : [ libc:: c_int ; 2 ] = [ libc:: CTL_KERN , libc:: KERN_ARND ] ;
7
- let mut len = buf . len ( ) ;
7
+ let mut len = cmp :: min ( len, libc :: ssize_t :: MAX . unsignd_abs ( ) ) ;
8
8
let ret = unsafe {
9
9
libc:: sysctl (
10
10
MIB . as_ptr ( ) ,
11
+ #[ allow( clippy:: cast_possible_truncation) ]
11
12
MIB . len ( ) as libc:: c_uint ,
12
13
buf. as_mut_ptr ( ) . cast :: < c_void > ( ) ,
13
14
& mut len,
@@ -18,7 +19,10 @@ fn kern_arnd(buf: &mut [MaybeUninit<u8>]) -> libc::ssize_t {
18
19
if ret == -1 {
19
20
-1
20
21
} else {
21
- len as libc:: ssize_t
22
+ // We clamped the request to `ssize_t::MAX` bytes so this lossless.
23
+ #[ allow( clippy:: cast_possible_truncation) ]
24
+ let len = len as libc:: ssize_t ;
25
+ len
22
26
}
23
27
}
24
28
You can’t perform that action at this time.
0 commit comments