Date: Wed, 12 Jun 1996 02:12:51 +0100 From: mark@linus.demon.co.uk (Mark Valentine) To: hackers@freebsd.org Subject: small sed bugfix (PR#908) Message-ID: <199606120112.CAA07808@linus.demon.co.uk>
next in thread | raw e-mail | index | archive | help
Can I tempt anyone to review and/or commit the tiny fix for an annoying sed bug which I submitted in December, with a view to having this or a similar fix in 2.1.5? It doesn't seem to make the sed regressions tests any noisier than they already were... I'm appending a copy of <http://www.freebsd.org/cgi-bin/query-pr.cgi?pr=908>. Cheers, Mark. -- 8< ------------------------------------------------------------------------- Problem Report bin/908 sed bug with trailing backslashes Confidential no Severity serious Priority medium Responsible freebsd-bugs@freebsd.org State open Class sw-bug Submitter-Id current-users Arrival-Date Thu Dec 21 17:00:01 PST 1995 Last-Modified Wed Dec 27 23:30:01 PST 1995 Originator Mark Valentine Organization Release FreeBSD 2.2-CURRENT i386 Environment n/a Description Sed misinterprets the pair of backslashes at the end of line 2 of the following script, resulting in line 3 being taken as part of the inserted text. 1i\ char foo[] = "\\ s/$/\\n\\/ $a\ "; GNU sed and SunOS 4.1.3 sed insert a single line ending with a backslash, and treat line three as a substition command. How-To-Repeat $ echo test | sed -f char foo[] = "\ s/$/\n\/ test "; $ echo test | /usr/gnu/bin/sed -f char foo[] = "\ test\n\ "; Fix Audit-Trail From: mark@linus.demon.co.uk (Mark Valentine) To: FreeBSD-gnats-submit@FreeBSD.ORG Cc: Subject: Re: bin/908: sed bug with trailing backslashes Date: Thu, 28 Dec 1995 07:19:57 +0000 > From: Mark Valentine > Date: Thu 21 Dec, 1995 > Subject: bin/908: sed bug with trailing backslashes > >Description: > > Sed misinterprets the pair of backslashes at the end of line 2 of > the following script, resulting in line 3 being taken as part of > the inserted text. > > 1i\ > char foo[] = "\\ > s/$/\\n\\/ > $a\ > "; This small patch to usr.bin/sed/compile.c seems to fix it. It replaces escaping backslashes in the input buffer with NULs, and uses those to determine whether the newline was escaped, rather than looking for a (possibly escaped) preceding backslash. --- compile.c.dist Wed Aug 16 21:21:55 1995 +++ compile.c Thu Dec 28 06:32:03 1995 @@ -628,11 +628,11 @@ EATSPACE(); for (; *p; p++) { if (*p == '\\') - p++; + *p++ = '\0'; *s++ = *p; } size += s - op; - if (p[-2] != '\\') { + if (p[-2] != '\0') { *s = '\0'; break; } This patch doesn't seem to break any of the regression tests. Mark. Unformatted -- 8< ------------------------------------------------------------------------- -- Mark Valentine at Home <mailto:mv@pobox.com> <http://www.pobox.com/~mv/>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199606120112.CAA07808>