about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-17 08:09:40 +0200
committerGitHub <noreply@github.com>2023-04-17 08:09:40 +0200
commit6e9a52cdc0c053f678757dca30df6b841df6408e (patch)
treee97f55890b232e0d2431b3ba5b3b6d5a934756f2
parentee9b8048265adbeb56ca35f20c251508db694532 (diff)
parent3dba5872a3b7e40e9c03aa89643266973c58fe1c (diff)
downloadrust-6e9a52cdc0c053f678757dca30df6b841df6408e.tar.gz
rust-6e9a52cdc0c053f678757dca30df6b841df6408e.zip
Rollup merge of #110388 - JohnBobbo96:remove-intrinsic-unwrap, r=the8472
Add a message for if an overflow occurs in `core::intrinsics::is_nonoverlapping`.
-rw-r--r--library/core/src/intrinsics.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index a7c100e1b23..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>().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.