aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-04-26 05:09:57 -0500
committerRob Landley <rob@landley.net>2021-04-26 05:09:57 -0500
commit773d404ee2b99797763012a32b317422ac18d64e (patch)
treed58f8669069582b5fe325c2e849f4f30b597f196
parent1a7ebb16ee72f4f19d3c1eae3c4c42cf8734cab9 (diff)
downloadtoybox-773d404ee2b99797763012a32b317422ac18d64e.tar.gz
Bugfix: sed s command couldn't skip initial match.
-rwxr-xr-xtests/sed.test1
-rw-r--r--toys/posix/sed.c2
2 files changed, 2 insertions, 1 deletions
diff --git a/tests/sed.test b/tests/sed.test
index c3928e58..fd3b2057 100755
--- a/tests/sed.test
+++ b/tests/sed.test
@@ -115,6 +115,7 @@ testing 'empty match after nonempty match' "sed -e 's/a*/c/g'" 'cbcncgc' \
testing 'empty match' "sed -e 's/[^ac]*/A/g'" 'AaAcA' '' 'abcde'
testing 's///#comment' "sed -e 's/TWO/four/i#comment'" "one\nfour\nthree" \
"" "one\ntwo\nthree"
+testing 's///num off end' 'sed -e s/e//2' 'e\n' '' 'e\n'
testing 'N flushes pending a and advances match counter' \
"sed -e 'a woo' -e 'N;\$p'" 'woo\none\ntwo\none\ntwo' "" 'one\ntwo'
diff --git a/toys/posix/sed.c b/toys/posix/sed.c
index 9bd05034..d5a4a833 100644
--- a/toys/posix/sed.c
+++ b/toys/posix/sed.c
@@ -443,7 +443,7 @@ static void sed_line(char **pline, long plen)
// If we're replacing only a specific match, skip if this isn't it
off = command->sflags>>4;
if (off && off != ++count) {
- memcpy(l2+l2used, rline, match[0].rm_eo);
+ if (l2) memcpy(l2+l2used, rline, match[0].rm_eo);
l2used += match[0].rm_eo;
rline += match[0].rm_eo;