From owner-freebsd-hackers Tue Jun 11 18:15:48 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id SAA13116 for hackers-outgoing; Tue, 11 Jun 1996 18:15:48 -0700 (PDT) Received: from linus.demon.co.uk (linus.demon.co.uk [158.152.10.220]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id SAA12913 for ; Tue, 11 Jun 1996 18:12:59 -0700 (PDT) Received: (from mark@localhost) by linus.demon.co.uk (8.7.5/8.7.3) id CAA07808 for hackers@freebsd.org; Wed, 12 Jun 1996 02:12:52 +0100 (BST) Message-Id: <199606120112.CAA07808@linus.demon.co.uk> From: mark@linus.demon.co.uk (Mark Valentine) Date: Wed, 12 Jun 1996 02:12:51 +0100 X-Mailer: Mail User's Shell (7.2.6 alpha(3) 7/19/95) To: hackers@freebsd.org Subject: small sed bugfix (PR#908) Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 . 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