fix dangling reference in Vec::append
This commit is contained in:
parent
f688ba6089
commit
f44b264447
2 changed files with 4 additions and 3 deletions
|
@ -1,5 +1,3 @@
|
||||||
#![cfg(not(miri))]
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::{usize, isize};
|
use std::{usize, isize};
|
||||||
|
@ -763,6 +761,7 @@ fn from_into_inner() {
|
||||||
it.next().unwrap();
|
it.next().unwrap();
|
||||||
let vec = it.collect::<Vec<_>>();
|
let vec = it.collect::<Vec<_>>();
|
||||||
assert_eq!(vec, [2, 3]);
|
assert_eq!(vec, [2, 3]);
|
||||||
|
#[cfg(not(miri))] // Miri does not support comparing dangling pointers
|
||||||
assert!(ptr != vec.as_ptr());
|
assert!(ptr != vec.as_ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,6 +970,7 @@ fn test_reserve_exact() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(not(miri))] // Miri does not support signalling OOM
|
||||||
fn test_try_reserve() {
|
fn test_try_reserve() {
|
||||||
|
|
||||||
// These are the interesting cases:
|
// These are the interesting cases:
|
||||||
|
@ -1073,6 +1073,7 @@ fn test_try_reserve() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(not(miri))] // Miri does not support signalling OOM
|
||||||
fn test_try_reserve_exact() {
|
fn test_try_reserve_exact() {
|
||||||
|
|
||||||
// This is exactly the same as test_try_reserve with the method changed.
|
// This is exactly the same as test_try_reserve with the method changed.
|
||||||
|
|
|
@ -1094,7 +1094,7 @@ impl<T> Vec<T> {
|
||||||
let count = (*other).len();
|
let count = (*other).len();
|
||||||
self.reserve(count);
|
self.reserve(count);
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
ptr::copy_nonoverlapping(other as *const T, self.get_unchecked_mut(len), count);
|
ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count);
|
||||||
self.len += count;
|
self.len += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue