csplit: avoid negate-with-overflow on an i32::MIN regex line offset - #13753
Open
leeewee wants to merge 1 commit into
Open
csplit: avoid negate-with-overflow on an i32::MIN regex line offset#13753leeewee wants to merge 1 commit into
leeewee wants to merge 1 commit into
Conversation
do_to_match computed `-offset as usize` for a negative `/regex/OFFSET` (or `%regex%OFFSET`) offset. When OFFSET is i32::MIN the negation has no i32 counterpart and overflows, panicking under overflow-checks. Use `offset.unsigned_abs()`, which yields the magnitude without overflowing, so the out-of-range offset produces the normal "line number out of range" error on every build.
Merging this PR will degrade performance by 18.29%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | df_with_path |
571.4 µs | 699.4 µs | -18.29% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing leeewee:csplit-fix-offset-negate-overflow (0c44621) with main (21d4e96)
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. ↩
|
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.
Fixes #13751
A
csplitregex pattern may carry a signed line offset —/regex/OFFSETor
%regex%OFFSET— parsed into ani32. For a negative offset,do_to_matchcomputed-offset as usize. WhenOFFSETisi32::MIN(
-2147483648), the negation has no positivei32counterpart andoverflows, panicking with
attempt to negate with overflowunderoverflow-checks (exit 134). GNU
csplitrejects the offset gracefully.Fix
Use
offset.unsigned_abs(), which yields the magnitude ofi32::MINwithout overflowing. The out-of-range offset then produces the normal
line number out of rangeerror, matching GNU (and uutils' own defaultrelease build).
Test
Adds
test_up_to_match_negative_offset_min_i32andtest_skip_to_match_negative_offset_min_i32, covering both the/regex/and
%regex%offset forms. They panic before the fix (the test build hasoverflow-checks enabled) and pass after.