fix: csplit --suffix-format huge field width panics instead of erroring#13256
Open
mvanhorn wants to merge 1 commit into
Open
fix: csplit --suffix-format huge field width panics instead of erroring#13256mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
Merging this PR will improve performance by 4.88%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
|
GNU testsuite comparison: |
Contributor
|
sorry but could you please rebase it ? thanks |
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.
Summary
csplitno longer panics when--suffix-formatrequests an enormous field width. A format like--suffix-format=%0999999999dnow returns a clean error instead of aborting with a Rust panic, because the split-name formatter propagates the formatting error rather than unwrapping it.Why this matters
Issue #12763 reports that
csplitpanics on a--suffix-formatwith a very large field width.SplitName::getusedwrite!/format!and unwrapped the result; for a pathological width the formatter allocation/formatting failed and the unwrap turned that into a panic, crashing the utility instead of reporting a usage error the way GNUcsplitdoes.The formatter now returns
io::Result<String>and the caller surfaces a propercspliterror, so an unusable suffix format is rejected with a message and a non-zero exit rather than a panic.Testing
cargo test -p uu_csplitpasses, including a newtest_csplitcase asserting that a huge--suffix-formatwidth errors out (non-zero exit, no panic) instead of crashing.cargo clippy -p uu_csplitis clean.Fixes #12763