Skip to content

Commit

Permalink
reverted back to checked_sub with adjusted castings
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyboylehub committed Nov 7, 2024
1 parent 1bfb5d3 commit f09e25e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions programs/mpl-hybrid/src/instructions/update_escrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ pub fn handler_update_escrow_v1(
escrow.authority = authority.key();
escrow.token = token.key();
escrow.fee_location = fee_location.key();

if let Some(name) = ix.name {
size_diff += name.len() as isize - escrow.name.len() as isize;
size_diff += (name.len() as isize)
.checked_sub(escrow.name.len() as isize)
.ok_or(MplHybridError::NumericalOverflow)?;
escrow.name = name;
}

if let Some(uri) = ix.uri {
size_diff += uri.len() as isize - escrow.uri.len() as isize;
size_diff += (uri.len() as isize)
.checked_sub(escrow.uri.len() as isize)
.ok_or(MplHybridError::NumericalOverflow)?;
escrow.uri = uri;
}
if let Some(max) = ix.max {
Expand All @@ -101,8 +107,9 @@ pub fn handler_update_escrow_v1(
escrow.path = path;
}

let new_size: isize = escrow.to_account_info().data_len() as isize + size_diff;

let new_size = (escrow.to_account_info().data_len() as isize)
.checked_add(size_diff)
.ok_or(MplHybridError::NumericalOverflow)?;
resize_or_reallocate_account_raw(
&escrow.to_account_info(),
authority,
Expand Down

0 comments on commit f09e25e

Please sign in to comment.