printf: avoid panic on numeric field width above u16::MAX - #14184
Open
MadeNavaneeth wants to merge 1 commit into
Open
printf: avoid panic on numeric field width above u16::MAX#14184MadeNavaneeth wants to merge 1 commit into
MadeNavaneeth wants to merge 1 commit into
Conversation
Widths between 65536 and MAX_FORMAT_WIDTH previously panicked with "Formatting argument out of range" because Rust's write! macro only accepts a u16 width. Replace the write! padding with manual space/zero padding (chunked) and keep the existing check_width guard, so widths above u16::MAX now format correctly and widths above the 1M guard still fail gracefully. Fixes uutils#13850
|
GNU testsuite comparison: |
Merging this PR will degrade performance by 10.16%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | split_lines |
9.2 ms | 10.6 ms | -13.16% |
| ❌ | Simulation | split_numeric_suffix |
9.7 ms | 11.1 ms | -12.55% |
| ❌ | Simulation | split_bytes |
644.5 µs | 675.1 µs | -4.53% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing MadeNavaneeth:fix/printf-width-u16-max (dd3e4ae) with main (0d8310c)
Footnotes
-
50 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13850.
printf '%65536d' 5panicked with "Formatting argument out of range" because Rust'swrite!macro only accepts a width that fits in au16. The boundary is exactlyu16::MAX:%65535dworked,%65536dpanicked (and any width up to the existingMAX_FORMAT_WIDTHguard of 1_000_000).This replaces the
write!-based padding innum_format::write_outputwith manual chunked space/zero padding (write_spaces/write_zeros), while keeping the existingcheck_widthguard so widths aboveMAX_FORMAT_WIDTHstill fail gracefully (matching GNU's behavior of erroring rather than hanging).Verified: the new regression tests
test_width_65536_does_not_panicandtest_width_above_u16_max_succeedspass, and the fulltest_printfsuite (142 tests) passes with no regressions.