csplit: a negative offset may not cross the split start - #14407
Open
Socialpranker wants to merge 1 commit into
Open
csplit: a negative offset may not cross the split start#14407Socialpranker wants to merge 1 commit into
Socialpranker wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
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.
For
/re/-N, GNU requires the target line (the match minusN) to be at orafter the first line of the current split; otherwise it fails:
uutils only checked that the target does not precede the start of the input
(
buffer_len() < offset), so a negative offset could silently reach back into aprevious split.
do_to_matchnow counts the lines of the current split readbefore the match (the ones carried over in the buffer plus the ones read in the
loop) and reports the existing
LineOutOfRangeerror when the offset exceedsthem. The old buffer-length check is the same test in the special case of the
first split, so it is dropped. Target line exactly at the split start stays a
valid (empty) split.
%re%-N,{N}repetitions,-k,-z,-sand--suppress-matchedall follow.Testing
tests/by-util/test_csplit.rs(exact stderr, status, and theabsence/presence of the split files). Mutation-checked: reverting
csplit.rsalone fails 4 of them.cargo test --features csplit --test tests test_csplit: 95 passed, 0 failed.cargo clippy -p uu_csplit --all-targets -- -D warningsandcargo fmt --check: clean.csplitinvocations(negative offsets shorter/equal/longer than the distance to the split start,
in the first, second and third split, with the options above, plus
/re/+Nand
%re%-Nfor contrast): 12 mismatches before, 0 after.black box; I did not read GNU coreutils source.
Disclosure
Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI policy
in CONTRIBUTING.md. All testing was run locally.