Subject: standards/15231: sed doesn't accept empty commands separated by semicolons
To: None <gnats-bugs@gnats.netbsd.org>
From: None <xmimic@free.fr>
List: netbsd-bugs
Date: 01/12/2002 16:12:53
>Number:         15231
>Category:       standards
>Synopsis:       sed doesn't accept empty commands separated by semicolons
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 13 02:25:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Aymeric Vincent
>Release:        NetBSD 1.5ZA
>Organization:
	
>Environment:
System: NetBSD smally 1.5ZA NetBSD 1.5ZA (SMALLY) #5: Fri Dec 21 11:23:49 CET 2001 vincent@ingrid:/usr/src/sys/arch/i386/compile/SMALLY i386
Architecture: i386
Machine: i386
>Description:
	% sed -e ';'
yields an error, while it can be argued that it should take this for an empty
command list.

Actually, this bug/feature appears when one uses --program-prefix in some
configure scripts, like the one shipped with nvi 1.81.5
(see pkgsrc/editors/nvi): it breaks.
The configure script generates two semicolons in sequence and this confuses our
sed.

I've changed that in my local copy of sed, but I don't know if any standard
defines what the behaviour should be. It looks like the semicolon is something
that is inherited from historical sed, and not described by the SUSv2 copy that
I have here. So I don't know if I should commit this, and I prefer to let
someone else decide.

>How-To-Repeat:
	% sed -e ';'
>Fix:
Index: compile.c
===================================================================
RCS file: /usr/local/cvsroot/basesrc/usr.bin/sed/compile.c,v
retrieving revision 1.19
diff -u -r1.19 compile.c
--- compile.c	1998/12/19 22:12:11	1.19
+++ compile.c	2002/01/12 13:05:14
@@ -172,8 +172,14 @@
 		}
 
 semicolon:	EATSPACE();
-		if (p && (*p == '#' || *p == '\0'))
-			continue;
+		if (p) {
+			if (*p == '#' || *p == '\0')
+				continue;
+			else if (*p == ';') {
+				p++;
+				goto semicolon;
+			}
+		}
 		*link = cmd = xmalloc(sizeof(struct s_command));
 		link = &cmd->next;
 		cmd->nonsel = cmd->inrange = 0;
>Release-Note:
>Audit-Trail:
>Unformatted: