Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version:content-type;
        bh=9xPznjC6iXOwk/VQxSqdQEh1V8z12kRPKaUnloXc1oI=;
        b=0cmhuwjRJ7z+nIU8HApvAd2mdp2R6xAHewQIupddg5roSg81yEcHw9WPfqq9zi3Fzd
         3i78BKw+TyaWTNx1BKkfXN6CoMrhm1CigUN6EGzbNqw+6FivVANfk/uiIMPZ7tbh4bSU
         BHy1MC7fP/w2XsS/D3QL9MutdifuETuWT0U3CNH3uK6cSC8yMe78AasXFnjcVSJvJaAv
         x/Y0sxfV3tpsuIq8JBio3Vma6i+Z9UwIXMMdsh6qu4li1ziVo4RiKji31EZ+FCy4RV5M
         5XPMMBriOxL+V5A3zzsVNoXPm1BExnh/KAvjzU0rkUCL5PZYdKATiu4u5C8GH21UGef2
         FEbQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version:content-type;
        bh=9xPznjC6iXOwk/VQxSqdQEh1V8z12kRPKaUnloXc1oI=;
        b=LIubp2SDKiXYtVoQ354TLIYb3d5M0ogbvk/cVrVHB4cgoxIc00SK241d0RM3rWNv8b
         CA0xpi8YuNn2qUAY181WUC+QWfJlxeDvo/fs3uxGmi3Gej3XpkEGWpfCYlVW6mVbnKbq
         lWmmYW+8lvMu0nnc395gAMdDo+dmhh9tQp/xDDKOYuv6IOK0N6EguUmWKtdyS6W3or7+
         xhweX4fIauHE9tEkaZD1IiLiZRo2dze4DWbz6nXT5ur69BweWiqbXA9A3ZZ6NmXhzKXD
         pNEBgso/xr0uo52uaSWI+hc28UOBu+J6Q65LwesTN6htEAZCpVUOOGaU2Y96yKghYn/+
         KKBQ==
X-Gm-Message-State: AG10YOQDehzTNjT/Awv6JUzMxRNNstIM2GylWyjGgZcKprnBB0fT/m+z72jyXfajUy9OZA==
X-Received: by 10.98.71.92 with SMTP id u89mr12537958pfa.122.1455402522159;
        Sat, 13 Feb 2016 14:28:42 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160213142857.ZM24181@torch.brasslantern.com>
Date: Sat, 13 Feb 2016 14:28:57 -0800
In-Reply-To: <CAPdr91afVtwZnv3o9FKqfgMeYg_1Tz9R-ujTVhJUwu4ErNtFng@mail.gmail.com>
Comments: In reply to Oscar Garcia Amor <ogarcia@connectical.com>
        "Segfault on completion with interactive mode" (Feb 10,  5:40pm)
References: <CAPdr91afVtwZnv3o9FKqfgMeYg_1Tz9R-ujTVhJUwu4ErNtFng@mail.gmail.com>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: Segfault on completion with interactive mode
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 37961

This seems to do it.  It may be possible to further reconcile the
(nmessages) branch with the print-our-own "no matches" branch, but
I haven't tried yet.  The idea is:

- there's no match for the current input, so there's nothing to be
  selected in the previously displayed set of possible matches
- the listing has been trashed anyway by displaying the warning
- so, don't bother attempting to redraw or to find the (nonexistent)
  selected item in the (trashed) list until after the next keystroke
  has been processed
- at which point the original listing has been redrawn and all is well.


diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c
index 937e1d1..162436b 100644
--- a/Src/Zle/complist.c
+++ b/Src/Zle/complist.c
@@ -34,8 +34,9 @@
 /* Information about the list shown. */
 
 /*
- * noselect: 1 if complistmatches indicated we shouldn't do selection.
- *           Tested in domenuselect.
+ * noselect: 1 if complistmatches indicated we shouldn't do selection;
+ *           -1 if interactive mode needs to reset the selection list.
+ *           Tested in domenuselect, and in complistmatches to skip redraw.
  * mselect:  Local copy of the index of the currently selected match.
  *           Initialised to the gnum entry of the current match for
  *           each completion.
@@ -1980,7 +1981,8 @@ complistmatches(UNUSED(Hookdef dummy), Chdata dat)
     }
 #endif
 
-    noselect = 0;
+    if (noselect > 0)
+	noselect = 0;
 
     if ((minfo.asked == 2 && mselect < 0) || nlnct >= zterm_lines) {
 	showinglist = 0;
@@ -2078,9 +2080,11 @@ complistmatches(UNUSED(Hookdef dummy), Chdata dat)
     last_cap = (char *) zhalloc(max_caplen + 1);
     *last_cap = '\0';
 
-    if (!mnew && inselect && onlnct == nlnct && mlbeg >= 0 && mlbeg == molbeg)
-        singledraw();
-    else if (!compprintlist(mselect >= 0) || !clearflag)
+    if (!mnew && inselect &&
+	onlnct == nlnct && mlbeg >= 0 && mlbeg == molbeg) {
+	if (!noselect)
+	    singledraw();
+    } else if (!compprintlist(mselect >= 0) || !clearflag)
 	noselect = 1;
 
     onlnct = nlnct;
@@ -2093,7 +2097,7 @@ complistmatches(UNUSED(Hookdef dummy), Chdata dat)
     popheap();
     opts[EXTENDEDGLOB] = extendedglob;
 
-    return noselect;
+    return (noselect < 0 ? 0 : noselect);
 }
 
 static int
@@ -2547,14 +2551,23 @@ domenuselect(Hookdef dummy, Chdata dat)
         } else {
             statusline = NULL;
         }
+	if (noselect < 0) {
+	    showinglist = clearlist = 0;
+	    clearflag = 1;
+	}
         zrefresh();
 	statusline = NULL;
         inselect = 1;
+	selected = 1;
         if (noselect) {
+	    if (noselect < 0) {
+		/* no selection until after processing keystroke */
+		noselect = 0;
+		goto getk;
+	    }
             broken = 1;
             break;
         }
-	selected = 1;
 	if (!i) {
 	    i = mcols * mlines;
 	    while (i--)
@@ -2752,6 +2765,7 @@ domenuselect(Hookdef dummy, Chdata dat)
 		if (nmessages) {
 		    showinglist = -2;
 		    zrefresh();
+		    noselect = -1;
 		} else {
 		    trashzle();
 		    zsetterm();

