Skip to content

Fix for #23150 #24269

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

Merged
merged 1 commit into from
Apr 11, 2015
Merged

Fix for #23150 #24269

merged 1 commit into from
Apr 11, 2015

Conversation

benashford
Copy link
Contributor

This fixes the bug described in issue #23150. This affected formatting any floating point number into a string in a formatting pattern that: a) required rounding up, and b) required an extra digit on the front.

So format!("{:.0}", 9.9) would fail, but format!("{:.0}", 8.9) would succeed. This was due to a negative integer being cast to a usize resulting in an 'arithmetic operation overflowed' panic.

The fix was to change the order of operations so that the number is zero before casting.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@alexcrichton
Copy link
Member

@bors: r+ faef52a

Thanks!

@bors
Copy link
Collaborator

bors commented Apr 11, 2015

⌛ Testing commit faef52a with merge d0340f5...

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 11, 2015
…ichton

 This fixes the bug described in issue rust-lang#23150.  This affected formatting any floating point number into a string in a formatting pattern that: a) required rounding up, and b) required an extra digit on the front.

So `format!(\"{:.0}\", 9.9)` would fail, but `format!(\"{:.0}\", 8.9)` would succeed.  This was due to a negative integer being cast to a `usize` resulting in an 'arithmetic operation overflowed' panic.

The fix was to change the order of operations so that the number is zero before casting.
@bors
Copy link
Collaborator

bors commented Apr 11, 2015

⛄ The build was interrupted to prioritize another pull request.

@bors
Copy link
Collaborator

bors commented Apr 11, 2015

⌛ Testing commit faef52a with merge 67a8f61...

bors added a commit that referenced this pull request Apr 11, 2015
This fixes the bug described in issue #23150.  This affected formatting any floating point number into a string in a formatting pattern that: a) required rounding up, and b) required an extra digit on the front.

So `format!("{:.0}", 9.9)` would fail, but `format!("{:.0}", 8.9)` would succeed.  This was due to a negative integer being cast to a `usize` resulting in an 'arithmetic operation overflowed' panic.

The fix was to change the order of operations so that the number is zero before casting.
@bors bors merged commit faef52a into rust-lang:master Apr 11, 2015
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.

5 participants