Skip to content

Commit

Permalink
Merge pull request #784 from RalfJung/as-byte-slice-mut
Browse files Browse the repository at this point in the history
fix extracting a u64 on little-endian CPUs
  • Loading branch information
dhardy committed Apr 23, 2019
2 parents 1f7af60 + b200923 commit 8f186ab
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions rand_core/src/block.rs
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 8f186ab

Please sign in to comment.