2
2
extern crate std;
3
3
4
4
use crate :: Error ;
5
- use std:: { sync:: mpsc, thread, vec, vec:: Vec } ;
5
+ use std:: { mem :: MaybeUninit , sync:: mpsc, thread, vec, vec:: Vec } ;
6
6
7
7
#[ cfg( feature = "test-in-browser" ) ]
8
8
wasm_bindgen_test:: wasm_bindgen_test_configure!( run_in_browser) ;
@@ -29,6 +29,15 @@ impl Byte for u8 {
29
29
v
30
30
}
31
31
}
32
+ impl Byte for MaybeUninit < u8 > {
33
+ fn make_vec ( len : usize , fill : FillFn < MaybeUninit < u8 > > ) -> Vec < u8 > {
34
+ // Ensure that we always get uninitialized memory.
35
+ let mut v = Vec :: with_capacity ( len) ;
36
+ fill ( v. spare_capacity_mut ( ) ) . unwrap ( ) ;
37
+ unsafe { v. set_len ( len) }
38
+ v
39
+ }
40
+ }
32
41
33
42
// For calls of size `len`, count the number of bits which differ between calls
34
43
// and check that between 3 and 5 bits per byte differ. Probability of failure:
@@ -112,3 +121,16 @@ macro_rules! define_tests {
112
121
pub ( crate ) use define_tests;
113
122
114
123
define_tests ! ( crate :: getrandom) ;
124
+ mod uninit {
125
+ use super :: * ;
126
+
127
+ fn wrapper ( dest : & mut [ MaybeUninit < u8 > ] ) -> Result < ( ) , Error > {
128
+ let dest_ptr = dest. as_ptr ( ) . cast :: < u8 > ( ) ;
129
+ let res = crate :: getrandom_uninit ( dest) ?;
130
+ // Ensure that the output points to the same bytes as the input.
131
+ assert_eq ! ( res. as_ptr( ) , dest_ptr) ;
132
+ assert_eq ! ( res. len( ) , dest. len( ) ) ;
133
+ Ok ( ( ) )
134
+ }
135
+ super :: define_tests!( wrapper) ;
136
+ }
0 commit comments