printf, seq: fix abort on large field width and precision#13460
Open
eyupcanakman wants to merge 1 commit into
Open
printf, seq: fix abort on large field width and precision#13460eyupcanakman wants to merge 1 commit into
eyupcanakman wants to merge 1 commit into
Conversation
A field width or precision above u16::MAX made Rust's formatting machinery panic, which the release build turns into a SIGABRT, so `printf '%70000d' 1` and `seq -f '%.70000f' 1 1` aborted where GNU pads the output. The %f formatter now assembles the decimal digits directly instead of going through bigdecimal's Display, which also fixes `printf '%.1000f' 1` printing `1` rather than `1.` and 1000 zeros (Display stops padding past 1000 digits). Padding is written in fixed chunks so a wide field costs no extra memory. Fixes uutils#12708
Merging this PR will improve performance by 18.37%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | seq_formatted |
94.7 ms | 80 ms | +18.37% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing eyupcanakman:fix/printf-large-width-precision-panic (76445dd) with main (8894319)
Footnotes
-
46 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. ↩
Contributor
|
Please fix the job issue |
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.
printfandseqabort with SIGABRT on a large field width or precision:Rust's formatting machinery panics once a dynamic width or precision passes
u16::MAX, and the release build turns that panic into an abort. GNU produces the padded output, so these now do too.While tracing it I found a second bug in the same path.
printf '%.1000f' 1printed1instead of1.and 1000 zeros, becausebigdecimal'sDisplaystops padding past 1000 digits. The%fformatter now assembles the digits directly, which fixes both. Padding is written in fixed chunks so a wide field costs no extra memory.#12620 uses the same chunked-padding approach for the width case. This also handles the large precision and the truncation, which #12620 and #12603 leave unfixed.
seq's own precision detection derives an unbounded value from the exponent text (seq 1e-3000000000 1e-3000000000), which this does not touch. That path is tracked in #13221.Fixes #12708