Resolve arith overflow on with_capacity#628
Merged
seanmonstar merged 3 commits intohyperium:masterfrom Nov 10, 2023
Merged
Conversation
hawkw
approved these changes
Sep 19, 2023
Contributor
hawkw
left a comment
There was a problem hiding this comment.
this looks good to me overall, thanks for the fix!
i had some minor suggestions for improving the panic messages so that the requested capacity is displayed to the user. what do you think?
Contributor
|
Function docstring should clarify this function panics: /// # Panics
///
/// Requested capacity too large: would overflow `usize`.
|
Contributor
Author
reflected! |
WhyNotHugo
reviewed
Sep 24, 2023
Comment on lines
+3231
to
+3237
| match n.checked_add(n / 3) { | ||
| Some(n) => n, | ||
| None => panic!( | ||
| "requested capacity {} too large: overflow while converting to raw capacity", | ||
| n | ||
| ), | ||
| } |
Contributor
There was a problem hiding this comment.
TBH, this could just be:
n.checked_add(n / 3).expect("requested capacity must fit usize without overflow")The only downside if that the requested capacity is not shown in the error, so maybe you'll want to hear what the maintainers think before applying any changes.
(the same applies to the above match that basically hand-rolls an expect).
seanmonstar
approved these changes
Nov 10, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
resolve #626 #627