Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: [RFC] crash with weird completer



On Tue, Mar 8, 2022 at 11:33 AM Mikael Magnusson <mikachu@xxxxxxxxx> 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);




Messages sorted by: Reverse Date, Date, Thread, Author