Skip to content

Commit b0c4a35

Browse files
committed
VecDeque::drain: make sure the 'drain' raw pointer is actually still usable
1 parent 21b5950 commit b0c4a35

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/liballoc/collections/vec_deque.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1019,14 +1019,19 @@ impl<T> VecDeque<T> {
10191019
// the drain is complete and the Drain destructor is run.
10201020
self.head = drain_tail;
10211021

1022+
// `deque` and `ring` overlap in what they point to, so we must make sure
1023+
// that `ring` is "derived-from" `deque`, or else even just creating ring
1024+
// from `self` already invalidates `deque`.
1025+
let deque = NonNull::from(&mut *self);
1026+
10221027
Drain {
1023-
deque: NonNull::from(&mut *self),
1028+
deque,
10241029
after_tail: drain_head,
10251030
after_head: head,
10261031
iter: Iter {
10271032
tail: drain_tail,
10281033
head: drain_head,
1029-
ring: unsafe { self.buffer_as_mut_slice() },
1034+
ring: unsafe { (&mut *deque.as_ptr()).buffer_as_mut_slice() },
10301035
},
10311036
}
10321037
}

0 commit comments

Comments
 (0)