Skip to content

Commit

Permalink
Fix Clippy warnings for VxWorks
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Jun 14, 2024
1 parent 78608a1 commit 92194cc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/vxworks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Implementation for VxWorks
use crate::{util_libc::last_os_error, Error};
use core::{
cmp::Ordering::{Equal, Greater, Less},
mem::MaybeUninit,
sync::atomic::{AtomicBool, Ordering::Relaxed},
};
Expand All @@ -9,17 +10,19 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
static RNG_INIT: AtomicBool = AtomicBool::new(false);
while !RNG_INIT.load(Relaxed) {
let ret = unsafe { libc::randSecure() };
if ret < 0 {
return Err(Error::VXWORKS_RAND_SECURE);
} else if ret > 0 {
RNG_INIT.store(true, Relaxed);
break;
match ret.cmp(&0) {
Greater => {
RNG_INIT.store(true, Relaxed);
break;
}
Equal => unsafe { libc::usleep(10); },
Less => return Err(Error::VXWORKS_RAND_SECURE),
}
unsafe { libc::usleep(10) };
}

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

0 comments on commit 92194cc

Please sign in to comment.