Skip to content

Commit

Permalink
Fix Vec::push_all ptr code in exception-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
guilliamxavier authored Aug 31, 2023
1 parent 388750b commit ac55a4c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/exception-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ impl<T: Clone> Vec<T> {
fn push_all(&mut self, to_push: &[T]) {
self.reserve(to_push.len());
unsafe {
let end_ptr = self.as_mut_ptr().add(self.len());
// can't overflow because we just reserved this
self.set_len(self.len() + to_push.len());
for (i, x) in to_push.iter().enumerate() {
self.ptr().add(i).write(x.clone());
end_ptr.add(i).write(x.clone());
}
}
}
Expand Down

0 comments on commit ac55a4c

Please sign in to comment.