From d7a8eea159b320244dff9514e9b0a33afeafe547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Fri, 14 Jun 2024 22:12:05 +0300 Subject: [PATCH] windows7: use `TryFrom` for `i32` to `usize` conversion --- src/windows7.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/windows7.rs b/src/windows7.rs index ff8ff0e0..6714f66b 100644 --- a/src/windows7.rs +++ b/src/windows7.rs @@ -25,7 +25,8 @@ const TRUE: BOOLEAN = 1u8; pub fn getrandom_inner(dest: &mut [MaybeUninit]) -> 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::(), chunk.len() as u32) }; if ret != TRUE { return Err(Error::WINDOWS_RTL_GEN_RANDOM);