Skip to content

Commit

Permalink
std: use cvt to handle errors from read_entropy on Hermit
Browse files Browse the repository at this point in the history
  • Loading branch information
joboet committed Mar 29, 2023
1 parent fdbf109 commit f6bde03
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions library/std/src/sys/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,9 @@ pub fn hashmap_random_keys() -> (u64, u64) {
let mut buf = [0; 16];
let mut slice = &mut buf[..];
while !slice.is_empty() {
let res = unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) };
if res < 0 {
panic!(
"random key generation failed: {}",
crate::io::Error::from_raw_os_error(-res as i32)
);
} else {
slice = &mut slice[res as usize..];
}
let res = cvt(unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) })
.expect("failed to generate random hashmap keys");
slice = &mut slice[res as usize..];
}

let key1 = buf[..8].try_into().unwrap();
Expand Down

0 comments on commit f6bde03

Please sign in to comment.