[comp.bugs.sys5] bug in ksh's vi editing

amos@taux01.UUCP (Amos Shapir) (06/28/89)

Index: ksh-i/src/sh/vi.c
Description:
 When editing commands in ksh's vi mode, a memory fault occurs which
 causes ksh to exit abnormally.
 
 Repeat by:
 	move to a line containing 7 chars (sometime any odd number would do);
 	then do
	x$rz
	(if the bug doesn't appear this should delete the 1st char
 	and replace the last one by 'z').
Fix:
	The 'x' command puts a blank at the end of the line, but forgets
	to put the terminating null back in.  A patch follows.

*** vi.c	Sun Jun 25 11:34:47 1989
--- vi.c.orig	Fri Nov 14 03:48:39 1986
***************
*** 1113,1119
  	virtual[++last_virt] = ' ';
  	if( mvcursor(motion)==BAD && strchr(";,TtFf", motion) )
  	{
! 		virtual[last_virt--] = 0;
  		return(BAD);
  	}
  	virtual[last_virt--] = 0;

--- 1113,1119 -----
  	virtual[++last_virt] = ' ';
  	if( mvcursor(motion)==BAD && strchr(";,TtFf", motion) )
  	{
! 		--last_virt;
  		return(BAD);
  	}
  	--last_virt;
***************
*** 1116,1122
  		virtual[last_virt--] = 0;
  		return(BAD);
  	}
! 	virtual[last_virt--] = 0;
  
  	j = cur_virt;
  	if( mode=='c' && j>i )

--- 1116,1122 -----
  		--last_virt;
  		return(BAD);
  	}
! 	--last_virt;
  
  	j = cur_virt;
  	if( mode=='c' && j>i )
-- 
	Amos Shapir				amos@nsc.com
National Semiconductor (Israel) P.O.B. 3007, Herzlia 46104, Israel
Tel. +972 52 522261  TWX: 33691, fax: +972-52-558322
34 48 E / 32 10 N			(My other cpu is a NS32532)