diff --git a/p-token/src/processor/close_account.rs b/p-token/src/processor/close_account.rs index 2156a6c..00f5e5a 100644 --- a/p-token/src/processor/close_account.rs +++ b/p-token/src/processor/close_account.rs @@ -11,6 +11,7 @@ use { }; #[inline(always)] +#[allow(clippy::arithmetic_side_effects)] pub fn process_close_account(accounts: &[AccountInfo]) -> ProgramResult { let [source_account_info, destination_account_info, authority_info, remaining @ ..] = accounts else { @@ -44,14 +45,13 @@ pub fn process_close_account(accounts: &[AccountInfo]) -> ProgramResult { } } - let destination_starting_lamports = destination_account_info.lamports(); // SAFETY: single mutable borrow to `destination_account_info` lamports and // there are no "active" borrows of `source_account_info` account data. unsafe { // Moves the lamports to the destination account. - *destination_account_info.borrow_mut_lamports_unchecked() = destination_starting_lamports - .checked_add(source_account_info.lamports()) - .ok_or(TokenError::Overflow)?; + // + // Note: The total lamports supply is bound to `u64::MAX`. + *destination_account_info.borrow_mut_lamports_unchecked() += source_account_info.lamports(); // Closes the source account. source_account_info.close_unchecked(); } diff --git a/p-token/src/processor/shared/burn.rs b/p-token/src/processor/shared/burn.rs index b4375ec..bf25f2b 100644 --- a/p-token/src/processor/shared/burn.rs +++ b/p-token/src/processor/shared/burn.rs @@ -8,6 +8,7 @@ use { }; #[inline(always)] +#[allow(clippy::arithmetic_side_effects)] pub fn process_burn( accounts: &[AccountInfo], amount: u64, @@ -83,8 +84,7 @@ pub fn process_burn( source_account.set_amount(updated_source_amount); // Note: The amount of a token account is always within the range of the // mint supply (`u64`). - let mint_supply = mint.supply().checked_sub(amount).unwrap(); - mint.set_supply(mint_supply); + mint.set_supply(mint.supply() - amount); } Ok(()) diff --git a/p-token/src/processor/withdraw_excess_lamports.rs b/p-token/src/processor/withdraw_excess_lamports.rs index 0ee7dfc..014ea27 100644 --- a/p-token/src/processor/withdraw_excess_lamports.rs +++ b/p-token/src/processor/withdraw_excess_lamports.rs @@ -86,13 +86,12 @@ pub fn process_withdraw_excess_lamports(accounts: &[AccountInfo]) -> ProgramResu source_starting_lamports - transfer_amount; } - let destination_starting_lamports = destination_info.lamports(); // SAFETY: single mutable borrow to `destination_info` lamports. unsafe { // Moves the lamports to the destination account. - *destination_info.borrow_mut_lamports_unchecked() = destination_starting_lamports - .checked_add(transfer_amount) - .ok_or(TokenError::Overflow)?; + // + // Note: The total lamports supply is bound to `u64::MAX`. + *destination_info.borrow_mut_lamports_unchecked() += transfer_amount; } Ok(())