Skip to content

Commit b7b9ce3

Browse files
authored
Rollup merge of #85610 - SkiFire13:fix-copy-within-provenance, r=oli-obk
Fix pointer provenance in <[T]>::copy_within Previously the `self.as_mut_ptr()` invalidated the pointer created by the first `self.as_ptr()`. This also triggered miri when run with `-Zmiri-track-raw-pointers`
2 parents d75521a + d7341f3 commit b7b9ce3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/core/src/slice/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3096,7 +3096,11 @@ impl<T> [T] {
30963096
// SAFETY: the conditions for `ptr::copy` have all been checked above,
30973097
// as have those for `ptr::add`.
30983098
unsafe {
3099-
ptr::copy(self.as_ptr().add(src_start), self.as_mut_ptr().add(dest), count);
3099+
// Derive both `src_ptr` and `dest_ptr` from the same loan
3100+
let ptr = self.as_mut_ptr();
3101+
let src_ptr = ptr.add(src_start);
3102+
let dest_ptr = ptr.add(dest);
3103+
ptr::copy(src_ptr, dest_ptr, count);
31003104
}
31013105
}
31023106

0 commit comments

Comments
 (0)