Skip to content

Commit d25797e

Browse files
committed
fix: change interval iter remaining_size to use saturing subtraction
include a debug assert to still catch the issues, but hopefully do less wrong behavior in release mode
1 parent 527e094 commit d25797e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

roaring/src/bitmap/store/interval_store.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,10 @@ impl<I: SliceIterator<Interval>> RunIter<I> {
693693
}
694694

695695
fn remaining_size(&self) -> usize {
696-
(self.intervals.as_slice().iter().map(|f| f.run_len()).sum::<u64>()
697-
- self.forward_offset as u64
698-
- self.backward_offset as u64) as usize
696+
let total_size = self.intervals.as_slice().iter().map(|f| f.run_len()).sum::<u64>();
697+
let total_offset = u64::from(self.forward_offset) + u64::from(self.backward_offset);
698+
debug_assert!(total_size >= total_offset);
699+
total_size.saturating_sub(total_offset) as usize
699700
}
700701

701702
/// Advance the iterator to the first value greater than or equal to `n`.

0 commit comments

Comments
 (0)