Skip to content

Commit

Permalink
sdk: replace sub() with saturating_sub()
Browse files Browse the repository at this point in the history
  • Loading branch information
t-nelson authored and Lichtso committed Aug 28, 2023
1 parent 382b9fb commit a32b94d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sdk/program/src/program_stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,14 @@ pub(crate) fn sol_get_epoch_rewards_sysvar(var_addr: *mut u8) -> u64 {
#[doc(hidden)]
pub fn is_nonoverlapping<N>(src: N, src_len: N, dst: N, dst_len: N) -> bool
where
N: Ord + std::ops::Sub<Output = N>,
<N as std::ops::Sub>::Output: Ord,
N: Ord + num_traits::SaturatingSub,
{
// If the absolute distance between the ptrs is at least as big as the size of the other,
// they do not overlap.
if src > dst {
src - dst >= dst_len
src.saturating_sub(&dst) >= dst_len
} else {
dst - src >= src_len
dst.saturating_sub(&src) >= src_len
}
}

Expand Down

0 comments on commit a32b94d

Please sign in to comment.