You're right. Yours is a lot cleaner.
OK martijn@
On 12/6/18 8:31 PM, Ingo Schwarze wrote:
> Hi Martijn,
>
> i think your patch does achieve the desired effect, but i'd prefer
> the following one instead. There is really no need to malloc(3) an
> empty string, only to later translate and free it.
>
> My version does not seems very dangerous. All it changes is that,
> if "b" or "t" is followed by optional whitespace, and then immediately
> by a semicolon, branching is set up to the end of the script -
> in exactly the same way as for "b" at the end of an input line -
> instead of to a label with an empty name, which never exists.
> Nothing else changes, in particular not parsing of subsequent input.
>
> The test suite still succeeds. Additional tests:
>
> $ echo "A\nB" | sed '1b;='
> A
> 2
> B
>
> $ echo "A\nB" | sed 's/A/C/;t;='
> C
> 2
> B
>
> $ echo "A\nB" | sed '1bL;=;:L'
> A
> 2
> B
>
> $ echo "1b\n=" > tmp.sed; echo "A\nB" | sed -f tmp.sed
> A
> 2
> B
>
> Yours,
> Ingo
>
>
> Index: compile.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/sed/compile.c,v
> retrieving revision 1.49
> diff -u -r1.49 compile.c
> --- compile.c 14 Aug 2018 18:10:09 -0000 1.49
> +++ compile.c 6 Dec 2018 19:07:31 -0000
> @@ -284,7 +284,7 @@
> case BRANCH: /* b t */
> p++;
> EATSPACE();
> - if (*p == '\0')
> + if (*p == '\0' || *p == ';')
> cmd->t = NULL;
> else
> cmd->t = duptoeol(p, "branch", &p);
>
>
>> 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;
>>