Use checked NonZero constructor in MIR move path indices
… to protect against UB in the unlikely case that `idx + 1` overflows.
This commit is contained in:
parent
13d17adf60
commit
06e130fb24
1 changed files with 1 additions and 1 deletions
|
|
@ -42,7 +42,7 @@ pub(crate) mod indexes {
|
|||
|
||||
impl Idx for $Index {
|
||||
fn new(idx: usize) -> Self {
|
||||
unsafe { $Index(NonZero::new_unchecked(idx + 1)) }
|
||||
$Index(NonZero::new(idx + 1).unwrap())
|
||||
}
|
||||
fn index(self) -> usize {
|
||||
self.0.get() - 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue