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;
        bh=p76yJ/varFZCYL8LOuDyw/2T4zCgLGYIquq1lJwjqT8=;
        b=CyTmToLUnhav2jho60IyzSPVgL9sP0LhhqhJ+FXDIBKbABaU3FSBfwqz7zUl2XpQI9
         Bxju6AXTiIuNRVoVP+nSJ7BAk5DdqaOV7ptnDCy6Ziq945e06l6fj1amx4zcZRxo5604
         UqfWg7aAWAtGnhN8p8PJT9luOvndMlvivKa7fWDqQQJ/DDFj0pt2nGoP2H5VyvNIZbTL
         KlLbix3W8ZWrKqtWxxbHogTeBwdemNC0l4ribMkLMBmojjZl8DAzjvlE8xuiQE+CgE3z
         HGt9NU1xZYoBCf6SEjVK1TZCzw7NR+9jN916+gHwNiH+TyPdEo6VSJibHLYeViMe7zOX
         KHvA==
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;
        bh=p76yJ/varFZCYL8LOuDyw/2T4zCgLGYIquq1lJwjqT8=;
        b=Siq2lWkjFSxM9XxVa9vCSORvaBKxH8TGN5k49csP2B3KnNhi/EBzVP6mfUwYgMzad4
         HfGpwwoZ6pAM4nOwYPOL0XYziogwDoyJLrRwGzpB2PbEDzrCInGV6FXLMnX538/eNeEi
         Z0unYxy8gAlyIG905+/D/gqwZKRnU3cMlbI6t3Rp3E9PNm7oZHc5HU1QOtSo/eVQr0YS
         I2PWLfp13AikkZAN+djA7wt7coFigCNRbjiw0PslTk8br8KFmdwWVeoXutjp2w541jq4
         1j3Vj6RwGHvpn4KJbPi1Nb5X6fxnRfBATzVypBKACuaslekCYYltEK90TUMMtwrYVG3t
         mM0w==
X-Gm-Message-State: AD7BkJKZy0KT3Ioq2f83azj/gd5bmARJ/lu3U/zqmRk71JAf2MwECeLEbQxxsI4mpzbU3w==
X-Received: by 10.98.19.195 with SMTP id 64mr33818301pft.62.1459559853205;
        Fri, 01 Apr 2016 18:17:33 -0700 (PDT)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160401181824.ZM23675@torch.brasslantern.com>
Date: Fri, 1 Apr 2016 18:18:24 -0700
In-Reply-To: <20160401053633.GA17993@tarsus.local2>
Comments: In reply to Daniel Shahaf <d.s@daniel.shahaf.name>
        "Re: Completion in empty double-quotes generates error" (Apr  1,  5:36am)
References: <160330110652.ZM1432@torch.brasslantern.com> 
	<20160401053633.GA17993@tarsus.local2>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Re: Completion in empty double-quotes generates error
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 38229

On Apr 1,  5:36am, Daniel Shahaf wrote:
} Subject: Re: Completion in empty double-quotes generates error
}
} Bart Schaefer wrote on Wed, Mar 30, 2016 at 11:06:52 -0700:
} > torch% ls ""<backward-char><complete-word>
} > torch% ls " ../../../zsh-5.0/Src/Zle/zle_tricky.c:658: BUG: 0 <= wb (3) <= zlemetacs (2) <= we (3) is not true!
} >        ls ""
} > 
} > If there is even one other character inside the quotes before completing, no
} > error is reported.
} 
} I ran into this six months ago in 37012

I'm not confident this is the same bug, even though the DPUTS() which
trips is the same one.

} there the reproducer was:
} 
} % : 2>1<backward-char><backward-char><<backward-char><complete-word>
} zle_tricky.c:658: BUG: 0 <= wb (4) <= zlemetacs (2) <= we (5) is not true!

I can't reproduce this any longer, at least not with plain compinit and
no zstyles.

In the empty-parens case, "wb" is set to the position of the first
double-quote and "we" is set to just after the second double-quote.
This happens in gotword() called from the lexer from get_comp_string()
at line 1202, via exalias().

Still in get_comp_string(), we then fall into the for-loop commented
/* While building the quoted form, we also clean up the command line. */

This loop deletes the double quotes with foredel() at line 1851, and
decrements we, but never adjusts wb even though the double-quote
at which it points is being deleted.  There's a similar thing with
backdel() in another branch, which presumably could be the 37021 bug,
but I don't know how to trigger it any more.

However, if I try what I think is obvious and set wb = zlemetacs then
the space before the double-quotes gets deleted and never restored.
So either it's not really a problem for zlemetacs to be less than wb,
or the following is correct (and I suppose its possible we need the
same test for wb > we, but I can't make that happen, so I'm leaving
it for now).

diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index a89b2a3..b1709c1 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -1849,8 +1849,12 @@ get_comp_string(void)
 		    ocs = zlemetacs;
 		    zlemetacs = i;
 		    foredel(skipchars, CUT_RAW);
-		    if ((zlemetacs = ocs) > --i)
+		    if ((zlemetacs = ocs) > --i) {
 			zlemetacs -= skipchars;
+			/* do not skip past the beginning of the word */
+			if (wb > zlemetacs)
+			    zlemetacs = wb;
+		    }
 		    we -= skipchars;
 		}
 	    } else {
@@ -1861,6 +1865,9 @@ get_comp_string(void)
 		    zlemetacs = we - skipchars;
 		else
 		    zlemetacs = ocs;
+		/* do not skip past the beginning of the word */
+		if (wb > zlemetacs)
+		    zlemetacs = wb;
 		we -= skipchars;
 	    }
 	    /* we need to get rid of all the quotation bits... */

