1
Fork 0

std: use cvt to handle errors from read_entropy on Hermit

This commit is contained in:
joboet 2023-03-29 10:52:48 +02:00
parent fdbf109b63
commit f6bde0352b
No known key found for this signature in database
GPG key ID: 704E0149B0194B3C

View file

@ -80,15 +80,9 @@ pub fn hashmap_random_keys() -> (u64, u64) {
let mut buf = [0; 16]; let mut buf = [0; 16];
let mut slice = &mut buf[..]; let mut slice = &mut buf[..];
while !slice.is_empty() { while !slice.is_empty() {
let res = unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) }; let res = cvt(unsafe { abi::read_entropy(slice.as_mut_ptr(), slice.len(), 0) })
if res < 0 { .expect("failed to generate random hashmap keys");
panic!( slice = &mut slice[res as usize..];
"random key generation failed: {}",
crate::io::Error::from_raw_os_error(-res as i32)
);
} else {
slice = &mut slice[res as usize..];
}
} }
let key1 = buf[..8].try_into().unwrap(); let key1 = buf[..8].try_into().unwrap();