zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: PATCH: [RFC] crash with weird completer
Date: Wed, 9 Mar 2022 21:47:58 -0800	[thread overview]
Message-ID: <CAH+w=7YoiRdzE9ewFRij-pRE4idpXGU=C7+b_TLNMba07uLzPw@mail.gmail.com> (raw)
In-Reply-To: <20220308193246.3204-1-mikachu@gmail.com>

On Tue, Mar 8, 2022 at 11:33 AM Mikael Magnusson <mikachu@gmail.com> wrote:
>
> type "foo " and press tab twice, and it should crash.

Alternate patch below.  This differs in that it initializes the
"lastprebr" array, which step is skipped by Mikael's patch.

> The patch prevents the crash but I have no further arguments that it's
> correct.

Ditto.

> Also without 'setopt nolistambiguous' we just get an additional
> { inserted for every tab press which also doesn't seem useful (not fixed
> by patch).

This is unrelated and I think connected to something mentioned
elsewhere; I can't find the reference at the moment, but IIRC the gist
is that because you're completing after an open brace, it's removed
from the prefix in expectation of completing a brace expansion, so the
suffix to be added then appears to begin with a brace, which is added
after the actual prefix on the line, resulting in doubled (etc.)
braces.

You can work around this by quoting the braces that should be treated literally:
    compdef _foo foo;_foo() { compadd -Q -- stash@\\{{0,1}\\} }

The patch:

diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 8b5955819..a1f2ec322 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -614,7 +614,7 @@ instmatch(Cmatch m, int *scs)
        l = 0;
        for (bp = brbeg, brpos = m->brpl,
                 bradd = (m->pre ? strlen(m->pre) : 0);
-            bp; bp = bp->next, brpos++) {
+            bp && brpos; bp = bp->next, brpos++) {
            zlemetacs = a + *brpos + bradd;
            pcs = zlemetacs;
            l = strlen(bp->str);


  reply	other threads:[~2022-03-10  5:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 19:32 Mikael Magnusson
2022-03-10  5:47 ` Bart Schaefer [this message]
2022-03-10 12:27   ` 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='CAH+w=7YoiRdzE9ewFRij-pRE4idpXGU=C7+b_TLNMba07uLzPw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=mikachu@gmail.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).