Skip to content

Commit

Permalink
Rollup merge of #106950 - the8472:fix-splice-miri, r=cuviper
Browse files Browse the repository at this point in the history
Don't do pointer arithmetic on pointers to deallocated memory

vec::Splice can invalidate the slice::Iter inside vec::Drain. So we replace them with dangling pointers which, unlike ones to deallocated memory, are allowed.

Fixes miri test failures.
Fixes #2759
  • Loading branch information
Dylan-DPC authored Jan 18, 2023
2 parents 3c9d6ba + 22fcfb2 commit 74a0bd1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/pass/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ fn reverse() {
assert!(v[0].0 == 49);
}

fn miri_issue_2759() {
let mut input = "1".to_string();
input.replace_range(0..0, "0");
}

fn main() {
assert_eq!(vec_reallocate().len(), 5);

Expand Down Expand Up @@ -191,4 +196,5 @@ fn main() {
swap();
swap_remove();
reverse();
miri_issue_2759();
}

0 comments on commit 74a0bd1

Please sign in to comment.