Skip to content

Commit

Permalink
feat: check variable addition overflow in debug
Browse files Browse the repository at this point in the history
  • Loading branch information
chrjabs committed Oct 18, 2024
1 parent 9c2bcbf commit e0932b1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,15 @@ impl ops::Add<u32> for Var {
type Output = Var;

fn add(self, rhs: u32) -> Self::Output {
Var {
idx: self.idx + rhs,
}
let idx = self.idx + rhs;
debug_assert!(idx <= Var::MAX_IDX);
Var { idx }
}
}

impl ops::AddAssign<u32> for Var {
fn add_assign(&mut self, rhs: u32) {
debug_assert!(self.idx + rhs <= Var::MAX_IDX);
self.idx += rhs;
}
}
Expand Down

0 comments on commit e0932b1

Please sign in to comment.