-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Check for Integer Overflow by Default #47739
Copy link
Copy link
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
It would be good to always check integers for overflow and thereby providing users with an integer type that actually behaves like an integer or at least fails completely instead of giving "wrong" results.
This was discussed on IRC last week and three distinct cases were identified:
My proposal is to make (1.) the default.
For (2.) there is already Wrapping but (3.) should also be annotated requiring people to assert that they have done their homework and
a) are sure that overflows cannot cause problems
b) the compiler cannot infer that the situation is safe and remove the checks
c) actually need the speed-up of omitting the checks.
I am aware that there are checked operations and compiler flags to keep overflow checks in release builds but the defaults are important and the defaults are wrong!
This issue is also discussed in the following two posts:
https://mail.mozilla.org/pipermail/rust-dev/2014-June/010363.html
https://huonw.github.io/blog/2016/04/myths-and-legends-about-integer-overflow-in-rust/