Skip to content

Commit 4a37b9c

Browse files
committed
Avoid overflow in VecDeque::with_capacity_in().
1 parent 5e02151 commit 4a37b9c

File tree

1 file changed

+1
-1
lines changed
  • library/alloc/src/collections/vec_deque

1 file changed

+1
-1
lines changed

library/alloc/src/collections/vec_deque/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
543543
/// ```
544544
#[unstable(feature = "allocator_api", issue = "32838")]
545545
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {
546+
assert!(capacity < 1_usize << usize::BITS - 1, "capacity overflow");
546547
// +1 since the ringbuffer always leaves one space empty
547548
let cap = cmp::max(capacity + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
548-
assert!(cap > capacity, "capacity overflow");
549549

550550
VecDeque { tail: 0, head: 0, buf: RawVec::with_capacity_in(cap, alloc) }
551551
}

0 commit comments

Comments
 (0)