From: Mohamed Akram Subject: Re: sed: check length before append in substitute To: "tech@openbsd.org" Date: Sat, 24 Aug 2024 09:02:18 +0000 Thoughts on this patch? > On Aug 16, 2024, at 6:33 PM, Mohamed Akram wrote: > > This resolves the case where the pattern space is empty but does not > start with a null character, which might occur after using the D > command. This can be seen in the following sed program, which should > print its input as-is: > > printf 'foo\n\n' | sed -e 's/^//p' -e '$!N' -e D > > --- src/usr.bin/sed/process.c.orig 2024-08-16 17:35:20 > +++ src/usr.bin/sed/process.c 2024-08-16 17:35:52 > @@ -387,14 +387,12 @@ > * and at the end of the line, terminate. > */ > if (match[0].rm_so == match[0].rm_eo) { > - if (*s == '\0' || *s == '\n') > - slen = -1; > - else > - slen--; > - if (*s != '\0') { > + if (slen > 0) { > cspace(&SS, s++, 1, APPEND); > + slen--; > le++; > - } > + } else > + slen = -1; > lastempty = 1; > } else > lastempty = 0; >