Skip to content

Add about overflow-checks flag in release mode #24

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iglesias
Copy link

Hi, I thought this can add a bit of information. Flag documentation.

Copy link
Collaborator

@PLeVasseur PLeVasseur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding some nuance @iglesias! Can you take a look at my comment?

saturating, or wrapping operations.

.. rationale::
:id: rat_kYiIiW8R2qD1
:status: draft

In debug builds, Rust performs runtime checks for integer overflow and will panic if detected.
However, in release builds (with optimizations enabled), integer operations silently wrap
around on overflow, creating potential for silent failures and security vulnerabilities.
However, in release builds (with optimizations enabled), unless the flag overflow-checks is
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While that will avoid overflow, I think that 'panic'ing may still be undesirable. I'd say if you added another sentence instead which described that silent wraps can be avoided with the overflow-checks flag, but we still panic, therefore we still advise being explicit that may work better. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think 'panic'inc is still undesirable in the context of this guideline's recommendation. I had considered whether it should be recommended adding it to the last sentence in the previous paragraph, then took a look at how the standard's library checked operation behaves (which is returning None) and decided not to. This change is about (probably a bit pedantically) note that the silent behavior isn't 100% implied by release / optimizations enabled. I will add another sentence here trying to clarify it.

@PLeVasseur
Copy link
Collaborator

FYI @iglesias -- #23 is merged, so you can rebase this.

@AchimKriso
Copy link

Here is some additional context from the language team that I think might be useful:
https://lang-team.rust-lang.org/frequently-requested-changes.html#numeric-overflow-checking-should-be-on-by-default-even-in-release-mode

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.

3 participants