File tree 1 file changed +5
-5
lines changed 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -794,15 +794,15 @@ impl Bitv {
794
794
let new_nblocks = blocks_for_bits ( new_nbits) ;
795
795
let full_value = if value { !0 } else { 0 } ;
796
796
797
- // Correct the old tail word
797
+ // Correct the old tail word, setting or clearing formerly unused bits
798
798
let old_last_word = blocks_for_bits ( self . nbits ) - 1 ;
799
799
if self . nbits % u32:: BITS > 0 {
800
- let overhang = self . nbits % u32:: BITS ; // # of already-used bits
801
- let mask = !( ( 1 << overhang) - 1 ) ; // e.g. 5 unused bits => 111110..0
800
+ let mask = mask_for_bits ( self . nbits ) ;
802
801
if value {
803
- self . storage [ old_last_word] |= mask;
802
+ self . storage [ old_last_word] |= ! mask;
804
803
} else {
805
- self . storage [ old_last_word] &= !mask;
804
+ // Extra bits are already supposed to be zero by invariant, but play it safe...
805
+ self . storage [ old_last_word] &= mask;
806
806
}
807
807
}
808
808
You can’t perform that action at this time.
0 commit comments