Skip to content

Commit

Permalink
Fix assertions inside read_{u32,u64}_into
Browse files Browse the repository at this point in the history
Unless I'm mistaken the size multiplier was on the wrong side, making the assertions too permissive. This could have resulted in destination buffers not being fully populated.
  • Loading branch information
tmandry committed Feb 11, 2021
1 parent 6ecbe26 commit 390a7b1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rand_core/src/le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use core::convert::TryInto;
/// Reads unsigned 32 bit integers from `src` into `dst`.
#[inline]
pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
assert!(4 * src.len() >= dst.len());
assert!(src.len() >= 4 * dst.len());
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(4)) {
*out = u32::from_le_bytes(chunk.try_into().unwrap());
}
Expand All @@ -25,7 +25,7 @@ pub fn read_u32_into(src: &[u8], dst: &mut [u32]) {
/// Reads unsigned 64 bit integers from `src` into `dst`.
#[inline]
pub fn read_u64_into(src: &[u8], dst: &mut [u64]) {
assert!(8 * src.len() >= dst.len());
assert!(src.len() >= 8 * dst.len());
for (out, chunk) in dst.iter_mut().zip(src.chunks_exact(8)) {
*out = u64::from_le_bytes(chunk.try_into().unwrap());
}
Expand Down

0 comments on commit 390a7b1

Please sign in to comment.