diff options
| author | John Bobbo <johnbobbo59@gmail.com> | 2023-04-16 07:29:14 -0700 |
|---|---|---|
| committer | John Bobbo <johnbobbo59@gmail.com> | 2023-04-16 07:35:18 -0700 |
| commit | 3dba5872a3b7e40e9c03aa89643266973c58fe1c (patch) | |
| tree | 3683e20acf06deaec7fdbfd6eee14a6a6afca4f5 | |
| parent | d0603fdafa61d1cc8c774f5845035d661093c7e9 (diff) | |
| download | rust-3dba5872a3b7e40e9c03aa89643266973c58fe1c.tar.gz rust-3dba5872a3b7e40e9c03aa89643266973c58fe1c.zip | |
Add a message indicating overflow in
`core::intrinsics::is_nonoverlapping`.
| -rw-r--r-- | library/core/src/intrinsics.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 44ed9f76c48..ba03da411e3 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -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>().saturating_mul(count); + 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. |
