zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Completion in empty double-quotes generates error
Date: Fri, 1 Apr 2016 18:18:24 -0700	[thread overview]
Message-ID: <160401181824.ZM23675@torch.brasslantern.com> (raw)
In-Reply-To: <20160401053633.GA17993@tarsus.local2>

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... */


  reply	other threads:[~2016-04-02  1:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 18:06 Bart Schaefer
2016-04-01  5:36 ` Daniel Shahaf
2016-04-02  1:18   ` Bart Schaefer [this message]
2016-04-02  3:29     ` Daniel Shahaf
2016-04-02  6:20       ` Bart Schaefer
2016-04-02 18:18         ` Bart Schaefer
2016-04-06 19:10           ` Bart Schaefer
2016-05-10 18:40             ` Daniel Shahaf
2016-05-10 20:13               ` Bart Schaefer
2016-05-10 21:00                 ` Bart Schaefer
2016-05-11 16:21                   ` Daniel Shahaf
2016-05-10 21:29                 ` Mikael Magnusson

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=160401181824.ZM23675@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /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).