Skip to content

Commit

Permalink
windows7: use TryFrom for i32 to usize conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Jun 14, 2024
1 parent d895bea commit d7a8eea
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/windows7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const TRUE: BOOLEAN = 1u8;

pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// Prevent overflow of u32
for chunk in dest.chunks_mut(u32::MAX as usize) {
let chunk_size = usize::try_from(i32::MAX).expect("Windows does not support 16-bit targets");
for chunk in dest.chunks_mut(chunk_size) {
let ret = unsafe { RtlGenRandom(chunk.as_mut_ptr().cast::<c_void>(), chunk.len() as u32) };
if ret != TRUE {
return Err(Error::WINDOWS_RTL_GEN_RANDOM);
Expand Down

0 comments on commit d7a8eea

Please sign in to comment.