Skip to content

Commit 7525864

Browse files
committed
fix: sys_rand() buf
1 parent 63a5f7e commit 7525864

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library/std/src/sys/random/zkvm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use crate::sys::pal::abi;
22

33
pub fn fill_bytes(bytes: &mut [u8]) {
4-
let (pre, words, post) = unsafe { bytes.align_to_mut::<u32>() };
4+
let (pre, words, post) = unsafe { bytes.align_to_mut::<u8>() };
55
if !words.is_empty() {
66
unsafe {
77
abi::sys_rand(words.as_mut_ptr(), words.len());
88
}
99
}
1010

11-
let mut buf = [0u32; 2];
11+
let mut buf = [0u8; 8];
1212
let len = (pre.len() + post.len() + size_of::<u32>() - 1) / size_of::<u32>();
1313
if len != 0 {
1414
unsafe { abi::sys_rand(buf.as_mut_ptr(), len) };
1515
}
1616

17-
let buf = buf.map(u32::to_ne_bytes);
17+
let buf = buf.map(u8::to_ne_bytes);
1818
let buf = buf.as_flattened();
1919
pre.copy_from_slice(&buf[..pre.len()]);
2020
post.copy_from_slice(&buf[pre.len()..pre.len() + post.len()]);

0 commit comments

Comments
 (0)