Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unsafe code from SeedableRng::seed_from_u64 #962

Merged
merged 2 commits into from Apr 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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