Skip to content
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 for issue #28012: pow overflow inconsistency #28248

Merged
merged 2 commits into from
Sep 14, 2015

Conversation

PeterReid
Copy link
Contributor

Overflows in integer pow() computations would be missed if they
preceded a 0 bit of the exponent being processed. This made
calls such as 2i32.pow(1024) not trigger an overflow.

Fixes #28012

Overflows in integer pow() computations would be missed if they
preceded a 0 bit of the exponent being processed. This made
calls such as 2i32.pow(1024) not trigger an overflow.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pcwalton (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 the contribution instructions for more information.

@ranma42
Copy link
Contributor

ranma42 commented Sep 5, 2015

Should we add a test for this?

@alexcrichton
Copy link
Member

Thanks! As @ranma42 mentioned, can you be sure to add a new test for this as well?

@alexcrichton alexcrichton assigned alexcrichton and unassigned pcwalton Sep 8, 2015
This would catch regressions of issue rust-lang#28012.
@PeterReid
Copy link
Contributor Author

Here's that test. It just checks that the 2^1024 computation from the original issue panics, structured the same way as several other run-fail/overflowing_*.rs tests.

@alexcrichton
Copy link
Member

@bors: r+ a593a21

Thanks!

@bors
Copy link
Contributor

bors commented Sep 14, 2015

⌛ Testing commit a593a21 with merge 9da7706...

bors added a commit that referenced this pull request Sep 14, 2015
Overflows in integer pow() computations would be missed if they
preceded a 0 bit of the exponent being processed. This made
calls such as 2i32.pow(1024) not trigger an overflow.

Fixes #28012
@bors bors merged commit a593a21 into rust-lang:master Sep 14, 2015
bors added a commit that referenced this pull request Sep 20, 2016
Fix overflow checking in unsigned pow()

The pow() method for unsigned integers produced 0 instead of trapping overflow for certain inputs. Calls such as 2u32.pow(1024) produced 0 when they should trap an overflow. This also adds tests for the correctly handling overflow in unsigned pow().

This was previously fixed for signed integers in #28248, but it seems unsigned integers got missed that time.

For issue number #34913
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.

6 participants