quick 7AM diff, may kill kittens.
martijn@
On 12/5/18 5:14 AM, Lars Noodén wrote:
> I'm noticing some trouble with branching in sed(1) now. Leaving the
> label empty should branch to the end of the script:
>
> [2addr]b [label]
> Branch to the : function with the specified label. If the label
> is not specified, branch to the end of the script.
>
> However, in practice, when I try branching without a label, I get an
> error about an undefined label instead of it branching to the end of
> the script:
>
> $ echo -e "START\nfoo\nbar\nEND\nbaz\n" | sed -n '/^START/,/^END/b;p;'
> sed: 1: "/^START/,/^END/b;p;": undefined label ''
>
> Adding a label works as expected:
>
> $ echo -e "START\nfoo\nbar\nEND\nbaz\n" | sed -n '/^START/,/^END/ba;p;:a;
>
> If I have not made a mistake with the short script above then there
> seems to be a discrepancy between the behavior described in the manual
> and the actual behavior.
>
> dmesg below
> /Lars
Index: compile.c
===================================================================
RCS file: /cvs/src/usr.bin/sed/compile.c,v
retrieving revision 1.49
diff -u -p -r1.49 compile.c
--- compile.c 14 Aug 2018 18:10:09 -0000 1.49
+++ compile.c 5 Dec 2018 06:02:15 -0000
@@ -797,7 +797,8 @@ fixuplabel(struct s_command *cp, struct
cp->u.c = NULL;
break;
}
- if ((cp->u.c = findlabel(cp->t)) == NULL)
+ if ((cp->u.c = findlabel(cp->t)) == NULL &&
+ *cp->t != '\0')
error(COMPILE, "undefined label '%s'", cp->t);
free(cp->t);
break;