Hi,
On 2025. 03. 05. 5:38, Jeremy Drake wrote:
in GNU sed, `echo foo | sed -e '/bar/{b};d'` is valid, but in busybox
sed would fail with unmatched {.
I beg to differ:
$ echo foo | sed -e 'bar{b};d'
sed: -e expression #1, char 6: unexpected `}'
$ sed --version
sed (GNU sed) 4.8
Packaged by Debian
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[...]
$ echo foo | busybox sed -e 'bar{b};d'
sed: can't find label for jump to 'ar{b}'
$ busybox sed --version
This is not GNU sed version 4.0
$ busybox
BusyBox v1.36.1 (2024-12-20 13:06:58 UTC) multi-call binary.
[...]
Signed-off-by: Jeremy Drake <[email protected]>
---
In strict posix, not even semicolon terminates a label, but busybox seems
to mostly follow GNU.
I'm not sure about the 'style' of this fix, there might be a more
idiomatic way to do this.
editors/sed.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/editors/sed.c b/editors/sed.c
index de411fbf4..6563c270c 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -133,7 +133,7 @@ typedef struct sed_cmd_s {
char cmd; /* The command char: abcdDgGhHilnNpPqrstwxy:={}
*/
} sed_cmd_t;
-static const char semicolon_whitespace[] ALIGN1 = "; \n\r\t\v";
+#define semicolon_whitespace "; \n\r\t\v"
struct globals {
/* options */
@@ -613,7 +613,7 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const
char *cmdstr)
int length;
cmdstr = skip_whitespace(cmdstr);
- length = strcspn(cmdstr, semicolon_whitespace);
+ length = strcspn(cmdstr, semicolon_whitespace "}");
I would much rather have a separate `static const char []` for this instead.
Bence
_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox