Skip to content

Commit

Permalink
Rollup merge of rust-lang#85610 - SkiFire13:fix-copy-within-provenanc…
Browse files Browse the repository at this point in the history
…e, 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`
  • Loading branch information
JohnTitor authored May 26, 2021
2 parents 75fced3 + d7341f3 commit 473e8ba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,11 @@ impl<T> [T] {
// SAFETY: the conditions for `ptr::copy` have all been checked above,
// as have those for `ptr::add`.
unsafe {
ptr::copy(self.as_ptr().add(src_start), self.as_mut_ptr().add(dest), count);
// Derive both `src_ptr` and `dest_ptr` from the same loan
let ptr = self.as_mut_ptr();
let src_ptr = ptr.add(src_start);
let dest_ptr = ptr.add(dest);
ptr::copy(src_ptr, dest_ptr, count);
}
}

Expand Down

0 comments on commit 473e8ba

Please sign in to comment.