Created attachment 144962 [details] Proposed patch for review There is a bug in "addr1,+N" ranges in the case of last input line, let's try: # seq 1 4 | sed -ne '1,+0p' 1 # seq 1 4 | sed -ne '1,+1p' 1 2 # seq 1 4 | sed -ne '1,+2p' 1 2 3 4 <--- This line should not be printed!!! # seq 1 4 | sed -ne '1,+3p' 1 2 3 4 The reason is that in case of AT_RELLINE, lastline()'s TRUE in MATCH() is taken before the test for relative range next (process.c:291-297): ... if (MATCH(cp->a2)) { cp->startline = 0; lastaddr = 1; r = 1; } else if (linenum - cp->startline <= cp->a2->u.l) r = 1; else if ((cp->a2->type == AT_LINE && ...
Thanks for reporting. I'll take care of it this weekend.
Created attachment 144995 [details] Fix sed relative address Here is the patch I propose. Would you mind testing it please? I did and it seems to work for me, but you cover some cases I haven't thought of. Additionally the patch untangles a bit the logic and makes the code easier to grasp, at the expense of being a bit longer
Hello, your patch seems good to me too, so please commit it ;o) Thank you very much.
A commit references this bug: Author: jlh Date: Wed Jul 30 14:46:40 UTC 2014 New revision: 269302 URL: http://svnweb.freebsd.org/changeset/base/269302 Log: Fix relative numerical addressing (addr,+N). As a bonus the patch untangles a bit the logic and makes the code easier to grasp. PR: 192108 MFC after: 1 week Changes: head/usr.bin/sed/process.c
A commit references this bug: Author: jlh Date: Mon Aug 11 20:38:52 UTC 2014 New revision: 269837 URL: http://svnweb.freebsd.org/changeset/base/269837 Log: MFC r269302: Fix relative numerical addressing (addr,+N). As a bonus the patch untangles a bit the logic and makes the code easier to grasp. PR: 192108 Changes: _U stable/10/ stable/10/usr.bin/sed/process.c
A commit references this bug: Author: jlh Date: Mon Aug 11 21:38:42 UTC 2014 New revision: 269841 URL: http://svnweb.freebsd.org/changeset/base/269841 Log: MFC r269302: Fix relative numerical addressing (addr,+N). As a bonus the patch untangles a bit the logic and makes the code easier to grasp. PR: 192108 Changes: _U stable/9/usr.bin/sed/ stable/9/usr.bin/sed/process.c
A commit references this bug: Author: jlh Date: Sat Jan 10 10:16:23 UTC 2015 New revision: 276909 URL: https://svnweb.freebsd.org/changeset/base/276909 Log: Add a regression test for PR 192108. I won't go through the hassle of MFCing it since I expect all changes to go first through HEAD anyway. PR: 192108 Changes: head/usr.bin/sed/tests/multi_test.sh head/usr.bin/sed/tests/regress.multitest.out/2.23