From nsayer@sftw.com  Tue May  9 16:43:35 2000
Return-Path: <nsayer@sftw.com>
Received: from guardian.sftw.com (guardian.sftw.com [209.157.37.25])
	by hub.freebsd.org (Postfix) with ESMTP id D292137B59B
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  9 May 2000 16:43:34 -0700 (PDT)
	(envelope-from nsayer@sftw.com)
Received: from yoda.sftw.com (yoda.sftw.com [209.157.37.211])
	by guardian.sftw.com (8.9.3/8.9.3) with ESMTP id QAA83507
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 9 May 2000 16:43:34 -0700 (PDT)
	(envelope-from nsayer@yoda.sftw.com)
Received: (from nsayer@localhost)
	by yoda.sftw.com (8.9.3/8.9.3) id QAA46021;
	Tue, 9 May 2000 16:43:38 -0700 (PDT)
	(envelope-from nsayer)
Message-Id: <200005092343.QAA46021@yoda.sftw.com>
Date: Tue, 9 May 2000 16:43:38 -0700 (PDT)
From: nsayer@freebsd.org
Sender: nsayer@sftw.com
Reply-To: nsayer@freebsd.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: sed i does not append newline
X-Send-Pr-Version: 3.2

>Number:         18474
>Category:       bin
>Synopsis:       sed i\ does not append newline
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 09 16:50:00 PDT 2000
>Closed-Date:    Thu May 11 10:03:39 PDT 2000
>Last-Modified:  Thu May 11 10:04:18 PDT 2000
>Originator:     Nick Sayer
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
Just me
>Environment:

Shell script bar:

#! /bin/sh

sed -e '3i\
foo' < foo

and foo contains:

1
2
3
4
5

>Description:

On FreeBSD, the output of script 'bar' is

1
2
foo3
4
5

On every other OS I have tried, the output is

1
2
foo
3
4
5

>How-To-Repeat:

See above.

>Fix:


--- usr.bin/sed/process.c.orig	Tue May  9 16:42:30 2000
+++ usr.bin/sed/process.c	Tue May  9 16:42:39 2000
@@ -157,7 +157,7 @@
 				cspace(&HS, ps, psl, 0);
 				break;
 			case 'i':
-				(void)printf("%s", cp->t);
+				(void)printf("%s\n", cp->t);
 				break;
 			case 'l':
 				lputs(ps);

>Release-Note:
>Audit-Trail:

From: Nick Sayer <nsayer@sftw.com>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/18474: sed i\ does not append newline
Date: Wed, 10 May 2000 10:45:55 -0700 (PDT)

 The patch above breaks sed -f. Instead, this patch explicitely
 appends a \n to -e arguments.
 
 --- main.c.orig	Wed May 10 10:31:02 2000
 +++ main.c	Wed May 10 10:33:36 2000
 @@ -114,6 +114,7 @@
  	char *argv[];
  {
  	int c, fflag;
 +	char *temp_arg;
  
  	(void) setlocale(LC_ALL, "");
  
 @@ -125,7 +126,10 @@
  			break;
  		case 'e':
  			eflag = 1;
 -			add_compunit(CU_STRING, optarg);
 +			temp_arg=malloc(strlen(optarg)+2);
 +			strcpy(temp_arg,optarg);
 +			strcat(temp_arg,"\n");
 +			add_compunit(CU_STRING, temp_arg);
  			break;
  		case 'f':
  			fflag = 1;
 
State-Changed-From-To: open->closed 
State-Changed-By: nsayer 
State-Changed-When: Thu May 11 10:03:39 PDT 2000 
State-Changed-Why:  
Committed (src/usr.sbin/sed/main.c, v1.11). 
>Unformatted:
