From oz@nixil.net  Thu Nov 17 00:01:13 2005
Return-Path: <oz@nixil.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CA67916A41F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Nov 2005 00:01:13 +0000 (GMT)
	(envelope-from oz@nixil.net)
Received: from nixil.net (nixil.net [161.58.222.1])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 71E9E43D46
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Nov 2005 00:01:13 +0000 (GMT)
	(envelope-from oz@nixil.net)
Received: from nixil.net (localhost [127.0.0.1])
	by nixil.net (8.13.1/8.13.1) with ESMTP id jAH01Ccb003245
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT)
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 16 Nov 2005 17:01:12 -0700 (MST)
Received: (from oz@localhost)
	by nixil.net (8.13.1/8.13.1/Submit) id jAH01CXW003244;
	Wed, 16 Nov 2005 17:01:12 -0700 (MST)
Message-Id: <200511170001.jAH01CXW003244@nixil.net>
Date: Wed, 16 Nov 2005 17:01:12 -0700 (MST)
From: Phil Oleson <oz@nixil.net>
Reply-To: Phil Oleson <oz@nixil.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: big fix for libedit
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         89180
>Category:       bin
>Synopsis:       [libedit] [patch] bug fix for libedit
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    stefanf
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 17 00:10:21 GMT 2005
>Closed-Date:    Mon Jan 09 18:16:21 GMT 2006
>Last-Modified:  Mon Jan 09 18:16:21 GMT 2006
>Originator:     Phil Oleson
>Release:        FreeBSD 4.7-RELEASE-p28 i386
>Organization:
N/A
>Environment:
System: FreeBSD nixil.net 4.7-RELEASE-p28 FreeBSD 4.7-RELEASE-p28 #42: Tue Jun 21 10:33:20 MDT 2005 root@fc2:/usr/src/sys/compile/VKERN i386


>Description:
	Here is the cvs log from netbsd:
--------------------------
revision 1.27
date: 2005/11/09 22:11:10;  author: christos;  state: Exp;  lines: +35 -13
Refresh bug reported by Julien Torres:

going from:
    activate -verbose
to:
    reset -activation
results in:
    reset -activationverbose"
instead of:
    reset -activation

This is because we choose to insert "reset -" before the current line,
and the delete "e -" and insert "ion" in the appropriate place. The
cleareol code did not handle this case properly; we now cleareol to
the maximum number of characters of the first difference, the second
difference and the difference in line length.
----------------------------

>How-To-Repeat:
	N/A
>Fix:

	Diff attached.

--- libedit-patch begins here ---
--- refresh.c.orig	Mon Nov 14 17:49:42 2005
+++ refresh.c	Mon Nov 14 18:00:05 2005
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: refresh.c,v 1.26 2003/08/07 16:44:33 agc Exp $
+ *	$NetBSD: refresh.c,v 1.27 2005/11/09 22:11:10 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -54,6 +54,7 @@
 private void	re_insert (EditLine *, char *, int, int, char *, int);
 private void	re_delete(EditLine *, char *, int, int, int);
 private void	re_fastputc(EditLine *, int);
+private void	re_clear_eol(EditLine *, int, int, int);
 private void	re__strncopy(char *, char *, size_t);
 private void	re__copy_and_pad(char *, const char *, size_t);
 
@@ -345,7 +346,7 @@
 	ELRE_DEBUG(1,
 	    (__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
 	    num, dat, dlen, d));
-	ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
+	ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
 
 	/* open up the space for num chars */
 	if (num > 0) {
@@ -358,7 +359,7 @@
 	ELRE_DEBUG(1, (__F,
 		"re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
 		num, dat, dlen, d));
-	ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
+	ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
 
 	/* copy the characters */
 	for (a = d + dat; (a < d + dlen) && (num > 0); num--)
@@ -367,7 +368,7 @@
 	ELRE_DEBUG(1,
 	    (__F, "re_insert() after copy: %d at %d max %d, %s == \"%s\"\n",
 	    num, dat, dlen, d, s));
-	ELRE_DEBUG(1, (__F, "s == \"%s\"n", s));
+	ELRE_DEBUG(1, (__F, "s == \"%s\"\n", s));
 }
 
 
@@ -416,6 +417,32 @@
 		*a++ = *b++;
 }
 
+/* re_clear_eol():
+ *	Find the number of characters we need to clear till the end of line
+ *	in order to make sure that we have cleared the previous contents of
+ *	the line. fx and sx is the number of characters inserted or deleted
+ *	int the first or second diff, diff is the difference between the
+ * 	number of characters between the new and old line.
+ */
+private void
+re_clear_eol(EditLine *el, int fx, int sx, int diff)
+{
+
+	ELRE_DEBUG(1, (__F, "re_clear_eol sx %d, fx %d, diff %d\n",
+	    sx, fx, diff));
+
+	if (fx < 0)
+		fx = -fx;
+	if (sx < 0)
+		sx = -sx;
+	if (fx > diff)
+		diff = fx;
+	if (sx > diff)
+		diff = sx;
+
+	ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff));
+	term_clear_EOL(el, diff);
+}
 
 /*****************************************************************
     re_update_line() is based on finding the middle difference of each line
@@ -631,7 +658,7 @@
 	fx = (nsb - nfd) - (osb - ofd);
 	sx = (nls - nse) - (ols - ose);
 
-	ELRE_DEBUG(1, (__F, "\n"));
+	ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx));
 	ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
 		ofd - old, osb - old, ose - old, ols - old, oe - old));
 	ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n",
@@ -780,9 +807,7 @@
 		         * write (nsb-nfd) chars of new starting at nfd
 		         */
 			term_overwrite(el, nfd, (nsb - nfd));
-			ELRE_DEBUG(1, (__F,
-			    "cleareol %d\n", (oe - old) - (ne - new)));
-			term_clear_EOL(el, (oe - old) - (ne - new));
+			re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
 			/*
 		         * Done
 		         */
@@ -823,10 +848,7 @@
 			ELRE_DEBUG(1, (__F,
 			    "but with nothing left to save\r\n"));
 			term_overwrite(el, nse, (nls - nse));
-			ELRE_DEBUG(1, (__F,
-			    "cleareol %d\n", (oe - old) - (ne - new)));
-			if ((oe - old) - (ne - new) != 0)
-				term_clear_EOL(el, (oe - old) - (ne - new));
+			re_clear_eol(el, fx, sx, (oe - old) - (ne - new));
 		}
 	}
 	/*
--- libedit-patch ends here ---


>Release-Note:
>Audit-Trail:

From: Phil Oleson <poleson@verio.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/89180: [libedit] [patch] big fix for libedit
Date: Wed, 16 Nov 2005 17:22:13 -0700

 s/big/bug/    sorry about that..

From: Phil Oleson <oz@nixil.net>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/89180: [libedit] [patch] big fix for libedit
Date: Wed, 16 Nov 2005 17:23:13 -0700

 s/big/bug     Sorry about that..
Responsible-Changed-From-To: freebsd-bugs->stefanf 
Responsible-Changed-By: stefanf 
Responsible-Changed-When: Sun Dec 4 09:39:02 GMT 2005 
Responsible-Changed-Why:  
Over to me. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=89180 
State-Changed-From-To: open->patched 
State-Changed-By: stefanf 
State-Changed-When: Sun Dec 4 09:39:27 GMT 2005 
State-Changed-Why:  
Just committed to current.  Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=89180 
State-Changed-From-To: patched->closed 
State-Changed-By: stefanf 
State-Changed-When: Mon Jan 9 18:16:18 UTC 2006 
State-Changed-Why:  
Also fixed in RELENG_{5,6}.  Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=89180 
>Unformatted:
