about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHans Kratz <hans@appfour.com>2021-10-18 13:15:45 +0200
committerHans Kratz <hans@appfour.com>2021-10-18 13:18:12 +0200
commit4a37b9cbffdc9ba66e9e4b7a17cb0de157a647f8 (patch)
tree854546843a4f523229366baadd53a2aed0f111c1
parent5e02151318ddd431aea6d58e23948246c1446044 (diff)
downloadrust-4a37b9cbffdc9ba66e9e4b7a17cb0de157a647f8.tar.gz
rust-4a37b9cbffdc9ba66e9e4b7a17cb0de157a647f8.zip
Avoid overflow in `VecDeque::with_capacity_in()`.
-rw-r--r--library/alloc/src/collections/vec_deque/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs
index c890ff4ac5e..de607c8fdab 100644
--- a/library/alloc/src/collections/vec_deque/mod.rs
+++ b/library/alloc/src/collections/vec_deque/mod.rs
@@ -543,9 +543,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
     /// ```
     #[unstable(feature = "allocator_api", issue = "32838")]
     pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {
+        assert!(capacity < 1_usize << usize::BITS - 1, "capacity overflow");
         // +1 since the ringbuffer always leaves one space empty
         let cap = cmp::max(capacity + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
-        assert!(cap > capacity, "capacity overflow");
 
         VecDeque { tail: 0, head: 0, buf: RawVec::with_capacity_in(cap, alloc) }
     }