fix ptr invalidation in Vec::truncate
This commit is contained in:
parent
86c1c43420
commit
fa6c883074
1 changed files with 2 additions and 1 deletions
|
@ -739,7 +739,8 @@ impl<T> Vec<T> {
|
||||||
if len > self.len {
|
if len > self.len {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let s = self.get_unchecked_mut(len..) as *mut _;
|
let remaining_len = self.len - len;
|
||||||
|
let s = slice::from_raw_parts_mut(self.as_mut_ptr().add(len), remaining_len);
|
||||||
self.len = len;
|
self.len = len;
|
||||||
ptr::drop_in_place(s);
|
ptr::drop_in_place(s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue