Skip to content

Commit 92194cc

Browse files
committed
Fix Clippy warnings for VxWorks
1 parent 78608a1 commit 92194cc

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/vxworks.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Implementation for VxWorks
22
use crate::{util_libc::last_os_error, Error};
33
use core::{
4+
cmp::Ordering::{Equal, Greater, Less},
45
mem::MaybeUninit,
56
sync::atomic::{AtomicBool, Ordering::Relaxed},
67
};
@@ -9,17 +10,19 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
910
static RNG_INIT: AtomicBool = AtomicBool::new(false);
1011
while !RNG_INIT.load(Relaxed) {
1112
let ret = unsafe { libc::randSecure() };
12-
if ret < 0 {
13-
return Err(Error::VXWORKS_RAND_SECURE);
14-
} else if ret > 0 {
15-
RNG_INIT.store(true, Relaxed);
16-
break;
13+
match ret.cmp(&0) {
14+
Greater => {
15+
RNG_INIT.store(true, Relaxed);
16+
break;
17+
}
18+
Equal => unsafe { libc::usleep(10); },
19+
Less => return Err(Error::VXWORKS_RAND_SECURE),
1720
}
18-
unsafe { libc::usleep(10) };
1921
}
2022

2123
// Prevent overflow of i32
22-
for chunk in dest.chunks_mut(i32::max_value() as usize) {
24+
let chunk_size = usize::try_from(i32::MAX).expect("VxWorks does not support 16-bit targets");
25+
for chunk in dest.chunks_mut(chunk_size) {
2326
let ret = unsafe { libc::randABytes(chunk.as_mut_ptr().cast::<u8>(), chunk.len() as i32) };
2427
if ret != 0 {
2528
return Err(last_os_error());

0 commit comments

Comments
 (0)