@@ -126,26 +126,27 @@ pub fn process_transfer(
126126 ( self_transfer, remaining_amount, delegated_amount)
127127 } ;
128128
129- // SAFETY: there is a single mutable borrow to `source_account_info` account data. The account
130- // is also guaranteed to be initialized.
131- let source_account =
132- unsafe { load_mut_unchecked :: < Account > ( source_account_info. borrow_mut_data_unchecked ( ) ) ? } ;
133-
134- // Updated the delegated amount if necessary.
135- if let Some ( delegated_amount) = delegated_amount {
136- source_account. set_delegated_amount ( delegated_amount) ;
137-
138- if delegated_amount == 0 {
139- source_account. clear_delegate ( ) ;
140- }
141- }
142-
143129 if self_transfer || amount == 0 {
144130 // Validates the token accounts owner since we are not writing
145131 // to these account.
146132 check_account_owner ( source_account_info) ?;
147133 check_account_owner ( destination_account_info) ?;
148134 } else {
135+ // SAFETY: there is a single mutable borrow to `source_account_info` account data. The account
136+ // is also guaranteed to be initialized.
137+ let source_account = unsafe {
138+ load_mut_unchecked :: < Account > ( source_account_info. borrow_mut_data_unchecked ( ) ) ?
139+ } ;
140+
141+ // Updated the delegated amount if necessary.
142+ if let Some ( delegated_amount) = delegated_amount {
143+ source_account. set_delegated_amount ( delegated_amount) ;
144+
145+ if delegated_amount == 0 {
146+ source_account. clear_delegate ( ) ;
147+ }
148+ }
149+
149150 // Moves the tokens.
150151
151152 source_account. set_amount ( remaining_amount) ;
0 commit comments