summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorjlh <jlh@FreeBSD.org>2014-08-11 20:38:52 +0000
committerjlh <jlh@FreeBSD.org>2014-08-11 20:38:52 +0000
commit2a07fd9787d8e4590d16e794e7b9dbbf8f0bfaf2 (patch)
treea9cc3ba9325f8f91a4121e270079c54f057e9b43 /usr.bin/sed
parentf8d542ba4ffd3be1835474a94d57f77b99f7d313 (diff)
downloadFreeBSD-src-2a07fd9787d8e4590d16e794e7b9dbbf8f0bfaf2.zip
FreeBSD-src-2a07fd9787d8e4590d16e794e7b9dbbf8f0bfaf2.tar.gz
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
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