Skip to content

printf: avoid panic on integer precision above u16::MAX#12579

Open
SAY-5 wants to merge 1 commit into
uutils:mainfrom
SAY-5:printf-large-precision
Open

printf: avoid panic on integer precision above u16::MAX#12579
SAY-5 wants to merge 1 commit into
uutils:mainfrom
SAY-5:printf-large-precision

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Jun 3, 2026

printf "%.100000d" 1 panics with "Formatting argument out of range" because the integer formatters feed the precision into format!("{:0>width$}"), and Rust's formatting machinery rejects a dynamic width/precision above u16::MAX. GNU prints the zero-padded number instead, so a large precision is valid input that should not crash.

This zero-pads the digits manually for the signed and unsigned integer paths, which removes the limit while keeping the existing output. Added a regression test that fails on the current code.

Fixes #12572.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

GNU testsuite comparison:

Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/printf/printf-surprise is now passing!

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.

bug: printf panic formatting argument out of range

1 participant