-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Out-Of-Range integers in format string literals silently wrap around #102528
Labels
C-bug
Category: This is a bug.
Comments
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Oct 14, 2022
Detect and reject out-of-range integers in format string literals Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes rust-lang#102528
lyming2007
pushed a commit
to lyming2007/rust
that referenced
this issue
Oct 21, 2022
Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes rust-lang#102528
Aaron1011
pushed a commit
to Aaron1011/rust
that referenced
this issue
Jan 6, 2023
Detect and reject out-of-range integers in format string literals Until now out-of-range integers in format string literals were silently ignored. They wrapped around to zero at usize::MAX, producing unexpected results. When using debug builds of rustc, such integers in format string literals even cause an 'attempt to add with overflow' panic in rustc. Fix this by producing an error diagnostic for integers in format string literals which do not fit into usize. Fixes rust-lang#102528
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried this code: (while learning Rust using Rust by Example and experimenting with the format string syntax available via format!() and related macros)
I expected to see this happen:
rustc
to reject this code with a diagnostic message due to the out of range integers in the format string literals.Instead, this happened:
rustc
compiled the code without any warning or error. Running the generated executable does not produce any assertion errors. This seems to be caused by the integers in the format string literals silently overflowing and wrapping around to zero.Note that when compiling the code with a selfbuilt debug build of
rustc
instead of the regular nightly build,rustc
panics due to an 'attempt to add with overflow':Backtrace
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: