From 7102b84a73a1564a4ef0a9bbabea509fa9fefe14 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 1 Aug 2022 19:15:16 -0400 Subject: [PATCH] Fix UB found by Miri --- src/byteset/scalar.rs | 2 +- src/ext_slice.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/byteset/scalar.rs b/src/byteset/scalar.rs index 8148daf..4d9fdd6 100644 --- a/src/byteset/scalar.rs +++ b/src/byteset/scalar.rs @@ -67,7 +67,7 @@ pub fn inv_memrchr(n1: u8, haystack: &[u8]) -> Option { let loop_size = cmp::min(LOOP_SIZE, haystack.len()); let align = USIZE_BYTES - 1; let start_ptr = haystack.as_ptr(); - let end_ptr = haystack[haystack.len()..].as_ptr(); + let end_ptr = unsafe { haystack.as_ptr().add(haystack.len()) }; let mut ptr = end_ptr; unsafe { diff --git a/src/ext_slice.rs b/src/ext_slice.rs index 2cc9649..b0287e9 100644 --- a/src/ext_slice.rs +++ b/src/ext_slice.rs @@ -3063,11 +3063,8 @@ pub trait ByteSlice: Sealed { // Finally, we are only dealing with u8 data, which is Copy, which // means we can copy without worrying about ownership/destructors. unsafe { - ptr::copy( - self.as_bytes().get_unchecked(src_start), - self.as_bytes_mut().get_unchecked_mut(dest), - count, - ); + let ptr = self.as_bytes_mut().as_mut_ptr(); + ptr::copy(ptr.add(src_start), ptr.add(dest), count); } } }