Skip to content

Conversation

@AriajSarkar
Copy link
Contributor

Summary

Fixes #785

Prevents panic in try_reserve() and try_with_capacity() when capacity calculations overflow. This fixes the API contract violation where try_* methods were panicking instead of returning Result.

Problem

The internal helper function to_raw_capacity() panics on arithmetic overflow:

fn to_raw_capacity(n: usize) -> usize {
    match n.checked_add(n / 3) {
        Some(n) => n,
        None => panic!("requested capacity {} too large...", n),
    }
}

Copy link
Member

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@seanmonstar seanmonstar merged commit 691af72 into hyperium:master Oct 27, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

try_reserve can panic despite "try" prefix suggesting error handling

2 participants