Skip to content

Commit

Permalink
fix extracting a u64 on little-endian CPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Apr 22, 2019
1 parent 476cb6d commit b200923
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rand_core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
#[inline(always)]
fn next_u64(&mut self) -> u64 {
let read_u64 = |results: &[u32], index| {
if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
// requires little-endian CPU supporting unaligned reads:
let ptr: *const u64 = results[index..index+1].as_ptr() as *const u64;
if cfg!(any(target_endian = "little")) {
// requires little-endian CPU
let ptr: *const u64 = results[index..=index+1].as_ptr() as *const u64;
unsafe { ptr::read_unaligned(ptr) }
} else {
let x = u64::from(results[index]);
Expand Down

0 comments on commit b200923

Please sign in to comment.