zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: PATCH: complist with long display lines
Date: Thu, 10 Aug 2006 01:01:02 -0700	[thread overview]
Message-ID: <060810010102.ZM24015@torch.brasslantern.com> (raw)
In-Reply-To: <20060809230445.6eb66ce0.p.w.stephenson@ntlworld.com>

On Aug 9, 11:04pm, Peter Stephenson wrote:
}
} The main completion code doesn't count an extra line for the screen for
} strings that exactly fit the screen width
} 
} The complist code, however, adds 1 to the count of lines (variously held
} in ml and mlprinted) if the number of columns just reaches the screen
} width.  As it only allocates the number of lines that the main
} completion code tells it, this causes bad array addressing.

Brilliant, Peter.  How did you ever track this down?

It may be worthwhile (or at least satisfying to paranoid types) to add
the following patch, which I've had sitting around uncommitted because
it failed to resolve the addressing issues that you seem to finally
have identified.  This patch prevents the infinite loop alluded to in
21842, by catching cases where an array index starts out negative and
decrements from there.  It might be unnecessary now, but:

Index: Src/Zle/complist.c
--- Src/Zle/complist.c	2006-08-10 00:34:13.000000000 -0700
+++ Src/Zle/complist.c.defense	2006-08-10 21:19:26.000000000 -0700
@@ -841,7 +831,7 @@
     selectlocalmap(NULL);
     settyinfo(&shttyinfo);
     putc('\r', shout);
-    for (i = columns - 1; i--; )
+    for (i = columns - 1; i-- > 0; )
 	putc(' ', shout);
     putc('\r', shout);
 
@@ -1162,7 +1148,7 @@
 		    if (mselect >= 0) {
 			int mm = (mcols * ml), i;
 
-			for (i = mcols; i--; ) {
+			for (i = mcols; i-- > 0; ) {
			    DPUTS(mm+i >= mgtabsize, "BUG: invalid position");
 			    mtab[mm + i] = mtmark(NULL);
 			    mgtab[mm + i] = mgmark(NULL);
@@ -1484,13 +1469,13 @@
 	    int mm = (mcols * ml), i;
 
             if (m->flags & CMF_DUMMY) {
-                for (i = mcols; i--; ) {
+                for (i = mcols; i-- > 0; ) {
		    DPUTS(mm+i >= mgtabsize, "BUG: invalid position");
                     mtab[mm + i] = mtmark(mp);
                     mgtab[mm + i] = mgmark(g);
                 }
             } else {
-                for (i = mcols; i--; ) {
+                for (i = mcols; i-- > 0; ) {
		    DPUTS(mm+i >= mgtabsize, "BUG: invalid position");
                     mtab[mm + i] = mp;
                     mgtab[mm + i] = g;
@@ -1545,13 +1523,13 @@
 	    int mm = mcols * ml, i;
 
             if (m->flags & CMF_DUMMY) {
-                for (i = (width ? width : mcols); i--; ) {
+                for (i = (width ? width : mcols); i-- > 0; ) {
		    DPUTS(mx+mm+i >= mgtabsize, "BUG: invalid position");
                     mtab[mx + mm + i] = mtmark(mp);
                     mgtab[mx + mm + i] = mgmark(g);
                 }
             } else {
-                for (i = (width ? width : mcols); i--; ) {
+                for (i = (width ? width : mcols); i-- > 0; ) {
		    DPUTS(mx+mm+i >= mgtabsize, "BUG: invalid position");
                     mtab[mx + mm + i] = mp;
                     mgtab[mx + mm + i] = g;
@@ -2184,7 +2142,7 @@
 	    Cmatch **p = mtab;
 
 	    for (y = 0; y < mlines; y++) {
-		for (x = mcols; x; x--, p++)
+		for (x = mcols; x > 0; x--, p++)
 		    if (*p && !mmarked(*p) && **p && mselect == (**p)->gnum)
 			break;
 		if (x) {
@@ -2195,7 +2153,7 @@
 	    int c;
 
 	    while (mlbeg) {
-		for (q = p, c = columns; c; q++, c--)
+		for (q = p, c = columns; c > 0; q++, c--)
 		    if (*q && !mmarked(*q))
 			break;
 		if (c)
@@ -2228,7 +2180,7 @@
 	    int c;
 
 	    while (mlbeg < mlines) {
-		for (q = p, c = columns; c; q++, c--)
+		for (q = p, c = columns; c > 0; q++, c--)
 		    if (*q)
 			break;
 		if (c)


  reply	other threads:[~2006-08-10  8:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-07 15:40 Peter Stephenson
2006-08-07 17:19 ` Bart Schaefer
2006-08-07 21:56   ` DervishD
2006-08-09 22:04   ` Peter Stephenson
2006-08-10  8:01     ` Bart Schaefer [this message]
2006-08-10  9:27       ` Peter Stephenson
2006-08-10 16:22     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=060810010102.ZM24015@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).