Skip to content

Commit

Permalink
Merge pull request #962 from Shnatsel/safe_seed_from_u64
Browse files Browse the repository at this point in the history
Drop unsafe code from SeedableRng::seed_from_u64
  • Loading branch information
dhardy committed Apr 6, 2020
2 parents 05a1273 + 5489851 commit 4a3a5cb
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions rand_core/src/lib.rs
Expand Up @@ -41,7 +41,6 @@

use core::convert::AsMut;
use core::default::Default;
use core::ptr::copy_nonoverlapping;

#[cfg(all(feature = "alloc", not(feature = "std")))] extern crate alloc;
#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::boxed::Box;
Expand Down Expand Up @@ -313,12 +312,8 @@ pub trait SeedableRng: Sized {
// Use PCG output function with to_le to generate x:
let xorshifted = (((state >> 18) ^ state) >> 27) as u32;
let rot = (state >> 59) as u32;
let x = xorshifted.rotate_right(rot).to_le();

unsafe {
let p = &x as *const u32 as *const u8;
copy_nonoverlapping(p, chunk.as_mut_ptr(), chunk.len());
}
let x = xorshifted.rotate_right(rot);
chunk.copy_from_slice(&x.to_le_bytes());
}

Self::from_seed(seed)
Expand Down

0 comments on commit 4a3a5cb

Please sign in to comment.