Skip to content

Commit 1d26463

Browse files
stegaBOBfebo
andauthored
Add resize_unchecked method to account info (#230)
* add resize_unchecked method to account info * Apply suggestion from @febo Co-authored-by: Fernando Otero <[email protected]> * Apply suggestion from @febo Co-authored-by: Fernando Otero <[email protected]> * Apply suggestion from @febo Co-authored-by: Fernando Otero <[email protected]> --------- Co-authored-by: Fernando Otero <[email protected]>
1 parent 17b0e86 commit 1d26463

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

sdk/pinocchio/src/account_info.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,22 @@ 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 { self.resize_unchecked(new_len) }
501+
}
502+
503+
/// Resize (either truncating or zero extending) the account's data.
504+
///
505+
/// The account data can be increased by up to [`MAX_PERMITTED_DATA_INCREASE`] bytes
506+
///
507+
/// # Safety
508+
///
509+
/// This method is unsafe because it does not check if the account data is already
510+
/// borrowed. The caller must guarantee that there are no active borrows to the account
511+
/// data.
512+
#[inline(always)]
513+
pub unsafe fn resize_unchecked(&self, new_len: usize) -> Result<(), ProgramError> {
498514
// Account length is always `< i32::MAX`...
499515
let current_len = self.data_len() as i32;
500516
// ...so the new length must fit in an `i32`.

0 commit comments

Comments
 (0)