summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorjlh <jlh@FreeBSD.org>2014-07-30 14:46:39 +0000
committerjlh <jlh@FreeBSD.org>2014-07-30 14:46:39 +0000
commitb23b8d4ef5420dc0dd0e98ff9b3ecf0c37b8ca29 (patch)
tree136d90d1b520b15d30ed4d9dece468eb6708fae7 /usr.bin/sed
parent5923a36c5e33028dfc8808fab94be4e10291bd74 (diff)
downloadFreeBSD-src-b23b8d4ef5420dc0dd0e98ff9b3ecf0c37b8ca29.zip
FreeBSD-src-b23b8d4ef5420dc0dd0e98ff9b3ecf0c37b8ca29.tar.gz
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
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/process.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index 5e2618a..a500200 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -288,24 +288,32 @@ applies(struct s_command *cp)
r = 1;
else if (cp->a2)
if (cp->startline > 0) {
- 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 &&
- linenum > cp->a2->u.l) ||
- (cp->a2->type == AT_RELLINE &&
- linenum - cp->startline > cp->a2->u.l)) {
- /*
- * We missed the 2nd address due to a branch,
- * so just close the range and return false.
- */
- cp->startline = 0;
- r = 0;
- } else
- r = 1;
+ switch (cp->a2->type) {
+ case AT_RELLINE:
+ if (linenum - cp->startline <= cp->a2->u.l)
+ r = 1;
+ else {
+ cp->startline = 0;
+ r = 0;
+ }
+ break;
+ default:
+ if (MATCH(cp->a2)) {
+ cp->startline = 0;
+ lastaddr = 1;
+ r = 1;
+ } else if (cp->a2->type == AT_LINE &&
+ linenum > cp->a2->u.l) {
+ /*
+ * We missed the 2nd address due to a
+ * branch, so just close the range and
+ * return false.
+ */
+ cp->startline = 0;
+ r = 0;
+ } else
+ r = 1;
+ }
} else if (MATCH(cp->a1)) {
/*
* If the second address is a number less than or
OpenPOWER on IntegriCloud