Skip to content

Commit 6789b45

Browse files
committed
add resize_unchecked method to account info
1 parent 4f47ad2 commit 6789b45

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

sdk/pinocchio/src/account_info.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,25 @@ impl AccountInfo {
495495
// Check wheather the account data is already borrowed.
496496
self.can_borrow_mut_data()?;
497497

498+
// SAFETY:
499+
// We are checking if the account data is already borrowed, so we are safe to call
500+
unsafe {
501+
self.resize_unchecked(new_len)?;
502+
}
503+
504+
Ok(())
505+
}
506+
507+
/// Resizes the account's data and udpates the resize delta without checking if the account is already borrowed.
508+
///
509+
/// The account data can be increased by up to [`MAX_PERMITTED_DATA_INCREASE`] bytes
510+
///
511+
/// # Safety
512+
///
513+
/// This method is unsafe because it does not check if the account data is already
514+
/// borrowed.
515+
#[inline(always)]
516+
pub unsafe fn resize_unchecked(&self, new_len: usize) -> Result<(), ProgramError> {
498517
// Account length is always `< i32::MAX`...
499518
let current_len = self.data_len() as i32;
500519
// ...so the new length must fit in an `i32`.

0 commit comments

Comments
 (0)