Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bounded: make sure lap does not overflow into index
.wrapping_add() is not enuough to ensure this, it is possible to end
up with index=1 if usize overflows. This is unlikely on 64-bit
systems, but possible on 32-bit systems.
  • Loading branch information
link2xt committed May 15, 2021
commit c8db484640bbfe662db3ea3a6e35ae5e65d186f8
4 changes: 2 additions & 2 deletions src/bounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<T> Bounded<T> {
} else {
// One lap forward, index wraps around to zero.
// Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`.
lap.wrapping_add(self.one_lap)
lap.wrapping_add(self.one_lap) & !(self.one_lap - 1)
};

// Try moving the tail.
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<T> Bounded<T> {
} else {
// One lap forward, index wraps around to zero.
// Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`.
lap.wrapping_add(self.one_lap)
lap.wrapping_add(self.one_lap) & !(self.one_lap - 1)
};

// Try moving the head.
Expand Down