printf: handle field widths above u16::MAX without panicking - #14162
printf: handle field widths above u16::MAX without panicking#14162MadeNavaneeth wants to merge 1 commit into
Conversation
Merging this PR will degrade performance by 5.52%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | true_consecutive_calls |
294.7 ns | 350.2 ns | -15.86% |
| ❌ | 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 µs | -4.52% |
| ❌ | Simulation | uniq_case_insensitive[10000] |
2.8 ms | 3 ms | -4.17% |
| ❌ | Simulation | uniq_with_count[10000] |
3.7 ms | 3.8 ms | -3.31% |
| ⚡ | Simulation | false_consecutive_calls |
350.2 ns | 294.7 ns | +18.85% |
| 🆕 | Memory | base16_encode_to_dev_null |
N/A | 22.6 KB | N/A |
| 🆕 | Memory | base16_encode_to_file |
N/A | 22.6 KB | N/A |
| 🆕 | Simulation | base16_encode_to_dev_null |
N/A | 184.3 ms | N/A |
| 🆕 | Simulation | base16_encode_to_file |
N/A | 184.2 ms | N/A |
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-large-field-width (3ee9e26) with main (1a6fb19)2
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. ↩
-
No successful run was found on
main(7d10e5b) during the generation of this report, so 1a6fb19 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
|
it needs a test |
|
GNU testsuite comparison: |
85f5fec to
c1446b6
Compare
Rust's write! macro panics with "Formatting argument out of range" when the width exceeds u16::MAX (65535). GNU printf accepts arbitrarily large field widths, so %65536d, %1000000d, etc. must not panic. Replace the write! macro calls in write_output() with manual padding using chunk-based write_spaces/write_zeros helpers, matching the approach already used in spec.rs for %s/%c formatting. Fixes uutils#13850
c1446b6 to
3ee9e26
Compare
Summary
Fixes #13850
The problem
Rusts
write!macro panics with "Formatting argument out of range" when the format width exceedsu16::MAX(65535). GNUprintfaccepts arbitrarily large field widths, so%65536d,%1000000d, etc. must not panic.The fix
Replace the
write!macro calls inwrite_output()with manual padding using chunk-basedwrite_spaces/write_zeroshelpers — the same approach already used inspec.rsfor%s/%cformatting.Verification
cargo clippy -p uucore -- -D warningsclean