Skip to content

sed: close addr,~N range when skipped target line has passed - #710

Merged
sylvestre merged 2 commits into
uutils:mainfrom
yunusarda-sudo:fix-step-end-skipped-lines
Nov 21, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
yunusarda-sudo:fix-step-end-skipped-lines

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

Fixes #655

Summary

An addr,~N range should end at the first line at or after addr whose line number is a multiple of N (or the subsequent multiple if addr is already a multiple of N).

Previously, Address::StepEnd(step) in applies() only checked whether the current line was an exact multiple of step (linenum.is_multiple_of(*step)), ignoring the computed end line target relative to start. If the exact target line was skipped (e.g., via an earlier d command, branch, or nested block), the range stayed open until the next multiple of step, or the end of input.

Solution

  • Compute the target line:
    let target = if *step == 0 {
        start
    } else {
        let rem = start % step;
        if rem == 0 {
            start + step
        } else {
            start + (step - rem)
        }
    };
  • When linenum >= target, close the range (command.start_line = None;) and set context.last_address = true;.
  • Added test cases in tests/by-util/test_sed.rs covering skipped end lines (3d;2,~3p, 3,4d;2,~3p) and starting on multiples (3,~3p).

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.44%. Comparing base (411cde9) to head (7cd4e9d).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #710   +/-   ##
=======================================
  Coverage   95.43%   95.44%           
=======================================
  Files          14       14           
  Lines        7740     7742    +2     
  Branches      467      467           
=======================================
+ Hits         7387     7389    +2     
  Misses        352      352           
  Partials        1        1           
Flag Coverage Δ
macos_latest 96.89% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 96.82% <100.00%> (+<0.01%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 3.52%

2 warnings

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 3 improved benchmarks
✅ 8 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ no_op_short 2.2 s 2.1 s +4.48%
⚡ access_log_no_op 1.6 s 1.5 s +3.1%
⚡ access_log_append 1.1 s 1 s +2.98%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing yunusarda-sudo:fix-step-end-skipped-lines (7cd4e9d) with main (24477d6)

Open in CodSpeed

Comment thread src/sed/processor.rs Outdated
Address::StepEnd(step) => {
// Inclusive end on multiple of step
if linenum.is_multiple_of(*step) {
let target = if *step == 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StepEnd(0) never sets start_line (see the StepEnd(0) case at line 161), so this branch is dead code.
let target = (start / step + 1) * step; would do, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated in 7cd4e9d to let target = (start / step + 1) * step;, eliminating the dead branch.

@sylvestre
sylvestre merged commit 6b247ff into uutils:main Nov 21, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sed - addr,~N range stays open when its end line never reaches the command

2 participants