about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-03-30 10:40:59 +0200
committerRalf Jung <post@ralfj.de>2020-03-30 11:58:16 +0200
commitfa6c8830740829d38f4ac7bfc8d8131ae44b9ade (patch)
tree6f4590debef177d6e1424dc73c5b6ca8ced6476a /src/liballoc
parent86c1c434206d5fb9b58b0847e2f4deb20340d3c5 (diff)
downloadrust-fa6c8830740829d38f4ac7bfc8d8131ae44b9ade.tar.gz
rust-fa6c8830740829d38f4ac7bfc8d8131ae44b9ade.zip
fix ptr invalidation in Vec::truncate
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/vec.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs
index 6f264399fa8..1c8c4428169 100644
--- a/src/liballoc/vec.rs
+++ b/src/liballoc/vec.rs
@@ -739,7 +739,8 @@ impl<T> Vec<T> {
             if len > self.len {
                 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;
             ptr::drop_in_place(s);
         }