File ksh93-vi.dif of Package ksh

--- src/cmd/ksh93/edit/vi.c
+++ src/cmd/ksh93/edit/vi.c	2014-02-17 15:53:10.873464619 +0000
@@ -396,6 +396,8 @@ int ed_viread(void *context, int fd, reg
 
 	if(!yankbuf)
 		yankbuf = (genchar*)malloc(MAXLINE*CHARSIZE);
+	if (!vp->lastline)
+		vp->lastline = (genchar*)malloc(MAXLINE*CHARSIZE);
 	if( vp->last_cmd == '\0' )
 	{
 		/*** first time for this shell ***/
@@ -405,6 +407,8 @@ int ed_viread(void *context, int fd, reg
 		vp->lastmotion = '\0';
 		vp->lastrepeat = 1;
 		vp->repeat = 1;
+		if (!yankbuf)
+			return(-1);
 		*yankbuf = 0;
 	}
 
@@ -1132,7 +1136,7 @@ static void cdelete(Vi_t *vp,register in
 
 		/*** save characters to be deleted ***/
 
-		if( mode != 'c' )
+		if( mode != 'c' && yankbuf )
 		{
 			i = cp[nchars];
 			cp[nchars] = 0;
@@ -2165,6 +2169,9 @@ static void save_last(register Vi_t* vp)
 {
 	register int i;
 
+	if (vp->lastline == NULL)
+		return;
+
 	if( (i = cur_virt - first_virt + 1) > 0 )
 	{
 		/*** save last thing user typed ***/
@@ -2414,6 +2421,11 @@ static int textmod(register Vi_t *vp,reg
 		p = yankbuf;
 	}
 
+	if (!p)
+	{
+		return(BAD);
+	}
+
 addin:
 	switch( c )
 	{
@@ -2686,6 +2698,8 @@ yankeol:
 		vp->lastmotion = c;
 		if( c == 'y' )
 		{
+			if (!yankbuf)
+				return(BAD);
 			gencpy(yankbuf, virtual);
 		}
 		else if(!delmotion(vp, c, 'y'))