Skip to content

Commit 66c1d24

Browse files
authored
use checked adds in counters (#3121)
1 parent 7a53112 commit 66c1d24

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/internet_identity/src/storage/storable/accounts_counter.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ impl StorableAccountsCounter {
2323
pub fn increment(&self, account_type: &AccountType) -> Self {
2424
match account_type {
2525
AccountType::AccountReference => Self {
26-
stored_account_references: self.stored_account_references + 1,
26+
stored_account_references: self
27+
.stored_account_references
28+
.checked_add(1)
29+
.expect("overflow in stored_account_references"),
2730
stored_accounts: self.stored_accounts,
2831
},
2932
AccountType::Account => Self {
30-
stored_accounts: self.stored_accounts + 1,
33+
stored_accounts: self
34+
.stored_accounts
35+
.checked_add(1)
36+
.expect("overflow in stored_accounts"),
3137
stored_account_references: self.stored_account_references,
3238
},
3339
}

src/internet_identity/src/storage/storable/discrepancy_counter.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ impl StorableDiscrepancyCounter {
2828
pub fn increment(&self, discrepancy_type: &DiscrepancyType) -> Self {
2929
match discrepancy_type {
3030
DiscrepancyType::AccountRebuild => Self {
31-
account_counter_rebuilds: self.account_counter_rebuilds + 1,
31+
account_counter_rebuilds: self
32+
.account_counter_rebuilds
33+
.checked_add(1)
34+
.expect("overflow in account_counter_rebuilds"),
3235
},
3336
}
3437
}

0 commit comments

Comments
 (0)