Fix capacity comparison in reserve

You can otherwise end up in a situation where you don't actually resize
but still call into handle_cap_increase which then corrupts head/tail.

Closes #44800
This commit is contained in:
Steven Fackler 2017-09-23 21:19:01 -07:00
parent 24831c7221
commit 9733463d2b

View File

@ -558,7 +558,7 @@ impl<T> VecDeque<T> {
.and_then(|needed_cap| needed_cap.checked_next_power_of_two()) .and_then(|needed_cap| needed_cap.checked_next_power_of_two())
.expect("capacity overflow"); .expect("capacity overflow");
if new_cap > self.capacity() { if new_cap > old_cap {
self.buf.reserve_exact(used_cap, new_cap - used_cap); self.buf.reserve_exact(used_cap, new_cap - used_cap);
unsafe { unsafe {
self.handle_cap_increase(old_cap); self.handle_cap_increase(old_cap);