Skip to content

Commit

Permalink
Fix checked arithmetic comparisons
Browse files Browse the repository at this point in the history
This commit fixes the improper checking of addition in the convenience
methods for the `Account` type.
  • Loading branch information
jmcph4 committed Apr 7, 2020
1 parent a57a0e4 commit 02afee2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Account {
pub fn add_balance(&mut self, amount: AccountBalance) ->
Result<(), AccountError> {
/* bounds check */
if self.balance.checked_add(amount) != None {
if self.balance.checked_add(amount).is_none() {
return Err(AccountError::BalanceOutOfBounds);
}

Expand All @@ -108,7 +108,8 @@ impl Account {
return Err(AccountError::AssetNotFound);
}

if self.holdings.get_mut(&ticker).unwrap().checked_add(amount) != None {
if self.holdings.get_mut(&ticker).unwrap().checked_add(amount).
is_none() {
return Err(AccountError::HoldingOutOfBounds);
}

Expand Down

0 comments on commit 02afee2

Please sign in to comment.