We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3e10e68 commit e6a64e4Copy full SHA for e6a64e4
consensus/types/src/test_utils/test_random/bitfield.rs
@@ -26,6 +26,15 @@ impl<N: Unsigned + Clone> TestRandom for BitVector<N> {
26
fn random_for_test(rng: &mut impl RngCore) -> Self {
27
let mut raw_bytes = smallvec![0; std::cmp::max(1, (N::to_usize() + 7) / 8)];
28
rng.fill_bytes(&mut raw_bytes);
29
+ // If N isn't divisible by 8
30
+ // zero out bits greater than N
31
+ if let Some(last_byte) = raw_bytes.last_mut() {
32
+ let mut mask = 0;
33
+ for i in 0..N::to_usize() % 8 {
34
+ mask |= 1 << i;
35
+ }
36
+ *last_byte &= mask;
37
38
Self::from_bytes(raw_bytes).expect("we generate a valid BitVector")
39
}
40
0 commit comments