Skip to content

Commit

Permalink
Rollup merge of #110388 - JohnBobbo96:remove-intrinsic-unwrap, r=the8472
Browse files Browse the repository at this point in the history
Add a message for if an overflow occurs in `core::intrinsics::is_nonoverlapping`.
  • Loading branch information
matthiaskrgr authored Apr 17, 2023
2 parents ee9b804 + 3dba587 commit 6e9a52c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,9 @@ pub(crate) fn is_valid_allocation_size<T>(len: usize) -> bool {
pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
let src_usize = src.addr();
let dst_usize = dst.addr();
let size = mem::size_of::<T>().checked_mul(count).unwrap();
let size = mem::size_of::<T>()
.checked_mul(count)
.expect("is_nonoverlapping: `size_of::<T>() * count` overflows a usize");
let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
// If the absolute distance between the ptrs is at least as big as the size of the buffer,
// they do not overlap.
Expand Down

0 comments on commit 6e9a52c

Please sign in to comment.