Skip to content

Commit f6bde03

Browse files
committed
std: use cvt to handle errors from read_entropy on Hermit
1 parent fdbf109 commit f6bde03

File tree

1 file changed

+3
-9
lines changed
  • library/std/src/sys/hermit

1 file changed

+3
-9
lines changed

library/std/src/sys/hermit/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,9 @@ pub fn hashmap_random_keys() -> (u64, u64) {
8080
let mut buf = [0; 16];
8181
let mut slice = &mut buf[..];
8282
while !slice.is_empty() {
83-
let res = unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) };
84-
if res < 0 {
85-
panic!(
86-
"random key generation failed: {}",
87-
crate::io::Error::from_raw_os_error(-res as i32)
88-
);
89-
} else {
90-
slice = &mut slice[res as usize..];
91-
}
83+
let res = cvt(unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) })
84+
.expect("failed to generate random hashmap keys");
85+
slice = &mut slice[res as usize..];
9286
}
9387

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

0 commit comments

Comments
 (0)