Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/header/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ impl<T> HeaderMap<T> {
if capacity == 0 {
Ok(Self::default())
} else {
let raw_cap = match to_raw_capacity(capacity).checked_next_power_of_two() {
let raw_cap = to_raw_capacity(capacity)?;
let raw_cap = match raw_cap.checked_next_power_of_two() {
Some(c) => c,
None => return Err(MaxSizeReached { _priv: () }),
};
Expand Down Expand Up @@ -750,7 +751,7 @@ impl<T> HeaderMap<T> {
.checked_add(additional)
.ok_or_else(MaxSizeReached::new)?;

let raw_cap = to_raw_capacity(cap);
let raw_cap = to_raw_capacity(cap)?;

if raw_cap > self.indices.len() {
let raw_cap = raw_cap
Expand Down Expand Up @@ -3621,14 +3622,8 @@ fn usable_capacity(cap: usize) -> usize {
}

#[inline]
fn to_raw_capacity(n: usize) -> usize {
match n.checked_add(n / 3) {
Some(n) => n,
None => panic!(
"requested capacity {} too large: overflow while converting to raw capacity",
n
),
}
fn to_raw_capacity(n: usize) -> Result<usize, MaxSizeReached> {
n.checked_add(n / 3).ok_or_else(MaxSizeReached::new)
}

#[inline]
Expand Down