Skip to content

Commit

Permalink
fix overflowing in PackedArray::get
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Aug 15, 2023
1 parent a9e87af commit b1540c2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/util/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl PackedArray {
let l = self.data[i];
let j = (index - i * self.elements_per_long) * self.element_bits;

l >> j & self.max_value
l.wrapping_shr(j as u32) & self.max_value
}

/// The backing data of this storage.
Expand Down Expand Up @@ -328,6 +328,9 @@ mod packed_array_tests {

assert_eq!(packed_array.get(4), 2);
assert_eq!(packed_array.get(35), 7);

assert!(packed_array.iter().any(|e| e == 2));
assert!(packed_array.iter().any(|e| e == 7));
}
}

Expand Down

0 comments on commit b1540c2

Please sign in to comment.