-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix integer overflow in format!("{:.0?}", Duration::MAX)
#102484
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (or someone else) soon. Please see the contribution instructions for more information. |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
8ee7167
to
e409ce2
Compare
Thanks for catching this! And I like the @bors r+ |
…=scottmcm Fix integer overflow in `format!("{:.0?}", Duration::MAX)` Currently `format!("{:.0?}", Duration::MAX)` causes an integer overflow in the `Duration` `Debug` impl ([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=67675c6895bdb2e37ee727f0ed7622b2)). This is because the carry from the rounding of the fractional_part into the integer_part will cause the integer_part to overflow as it is already `u64::MAX`. This PR uses a larger integer type to avoid that issue, and adds a test for the correct behaviour.
☀️ Test successful - checks-actions |
Finished benchmarking commit (75d3027): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
Currently
format!("{:.0?}", Duration::MAX)
causes an integer overflow in theDuration
Debug
impl (playground link). This is because the carry from the rounding of the fractional_part into the integer_part will cause the integer_part to overflow as it is alreadyu64::MAX
. This PR uses a larger integer type to avoid that issue, and adds a test for the correct behaviour.