Skip to content

Commit 4a3a5cb

Browse files
authored
Merge pull request #962 from Shnatsel/safe_seed_from_u64
Drop unsafe code from SeedableRng::seed_from_u64
2 parents 05a1273 + 5489851 commit 4a3a5cb

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

rand_core/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141

4242
use core::convert::AsMut;
4343
use core::default::Default;
44-
use core::ptr::copy_nonoverlapping;
4544

4645
#[cfg(all(feature = "alloc", not(feature = "std")))] extern crate alloc;
4746
#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::boxed::Box;
@@ -313,12 +312,8 @@ pub trait SeedableRng: Sized {
313312
// Use PCG output function with to_le to generate x:
314313
let xorshifted = (((state >> 18) ^ state) >> 27) as u32;
315314
let rot = (state >> 59) as u32;
316-
let x = xorshifted.rotate_right(rot).to_le();
317-
318-
unsafe {
319-
let p = &x as *const u32 as *const u8;
320-
copy_nonoverlapping(p, chunk.as_mut_ptr(), chunk.len());
321-
}
315+
let x = xorshifted.rotate_right(rot);
316+
chunk.copy_from_slice(&x.to_le_bytes());
322317
}
323318

324319
Self::from_seed(seed)

0 commit comments

Comments
 (0)