Skip to content

Commit

Permalink
Protect against passing i128::MIN to abs() which causes overflow (#…
Browse files Browse the repository at this point in the history
…2241)

## Linked Issues
Closes #2210

## Description
This PR uses `saturating_abs()` instead of "raw" `abs()` inside the
`da_change()` to prevent overflow on `i128::MIN`.

### Before requesting review
- [X] I have reviewed the code myself

---------

Co-authored-by: Mitchell Turner <james.mitchell.turner@gmail.com>
  • Loading branch information
rafal-ch and MitchTurner authored Sep 25, 2024
1 parent 1e2bcdc commit 20812f1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/fuel-gas-price-algorithm/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl AlgorithmUpdaterV1 {
.saturating_mul(upcast_percent)
.saturating_div(100)
.into();
let clamped_change = pd_change.abs().min(max_change);
let clamped_change = pd_change.saturating_abs().min(max_change);
pd_change.signum().saturating_mul(clamped_change)
}

Expand Down

0 comments on commit 20812f1

Please sign in to comment.