about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-09-27 01:23:24 +0000
committerbors <bors@rust-lang.org>2017-09-27 01:23:24 +0000
commitf71b37bc28326e272a37b938e835d4f99113eec2 (patch)
tree76f1c334ca4582001db86999c23fce03ba70a04f /src/liballoc
parentd4da74424729fd27e007dbcf6858201515f3e971 (diff)
parent81bac74c2ddc6c39f3628a36966f4a56a1282d02 (diff)
downloadrust-f71b37bc28326e272a37b938e835d4f99113eec2.tar.gz
rust-f71b37bc28326e272a37b938e835d4f99113eec2.zip
Auto merge of #44802 - sfackler:vecdeque-oob, r=Gankro
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

Not totally sure the right way to write a test for this - there are some debug asserts the old bad behavior will hit but we don't build the stdlib with debug assertions by default.

r? @Gankro
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/vec_deque.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs
index 6836fbb7c4d..6d64e9e303f 100644
--- a/src/liballoc/vec_deque.rs
+++ b/src/liballoc/vec_deque.rs
@@ -558,7 +558,7 @@ impl<T> VecDeque<T> {
             .and_then(|needed_cap| needed_cap.checked_next_power_of_two())
             .expect("capacity overflow");
 
-        if new_cap > self.capacity() {
+        if new_cap > old_cap {
             self.buf.reserve_exact(used_cap, new_cap - used_cap);
             unsafe {
                 self.handle_cap_increase(old_cap);