Skip to content

Commit f44b264

Browse files
committed
fix dangling reference in Vec::append
1 parent f688ba6 commit f44b264

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: src/liballoc/tests/vec.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))]
2-
31
use std::borrow::Cow;
42
use std::mem::size_of;
53
use std::{usize, isize};
@@ -763,6 +761,7 @@ fn from_into_inner() {
763761
it.next().unwrap();
764762
let vec = it.collect::<Vec<_>>();
765763
assert_eq!(vec, [2, 3]);
764+
#[cfg(not(miri))] // Miri does not support comparing dangling pointers
766765
assert!(ptr != vec.as_ptr());
767766
}
768767

@@ -971,6 +970,7 @@ fn test_reserve_exact() {
971970
}
972971

973972
#[test]
973+
#[cfg(not(miri))] // Miri does not support signalling OOM
974974
fn test_try_reserve() {
975975

976976
// These are the interesting cases:
@@ -1073,6 +1073,7 @@ fn test_try_reserve() {
10731073
}
10741074

10751075
#[test]
1076+
#[cfg(not(miri))] // Miri does not support signalling OOM
10761077
fn test_try_reserve_exact() {
10771078

10781079
// This is exactly the same as test_try_reserve with the method changed.

Diff for: src/liballoc/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ impl<T> Vec<T> {
10941094
let count = (*other).len();
10951095
self.reserve(count);
10961096
let len = self.len();
1097-
ptr::copy_nonoverlapping(other as *const T, self.get_unchecked_mut(len), count);
1097+
ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count);
10981098
self.len += count;
10991099
}
11001100

0 commit comments

Comments
 (0)