From b38ebc05386102e78ac3cae92f0c9778bcd0ce8f Mon Sep 17 00:00:00 2001 From: Jeremie Le Hen Date: Wed, 30 Jul 2014 14:46:39 +0000 Subject: [PATCH] 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 --- usr.bin/sed/process.c | 44 +++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index 5e2618ae98fd..a500200dd87d 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