Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: [RFC] crash with weird completer
- X-seq: zsh-workers 49820
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: [RFC] crash with weird completer
- Date: Thu, 10 Mar 2022 13:27:18 +0100
- Archived-at: <https://zsh.org/workers/49820>
- In-reply-to: <CAH+w=7YoiRdzE9ewFRij-pRE4idpXGU=C7+b_TLNMba07uLzPw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20220308193246.3204-1-mikachu@gmail.com> <CAH+w=7YoiRdzE9ewFRij-pRE4idpXGU=C7+b_TLNMba07uLzPw@mail.gmail.com>
On 3/10/22, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 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.
>
> You can work around this by quoting the braces that should be treated
> literally:
> compdef _foo foo;_foo() { compadd -Q -- stash@\\{{0,1}\\} }
I don't remember the thought process that led to the test case, but in
that case you could just drop the -Q too, right?
> The patch:
Hmm, I guess this is safer in the case that somehow m->brpl is set but
a subsequent brpos is NULL. It's probably (definitely) not worth
bothering about skipping NULL entries to process other ones (eg,
continue instead of break when !brpos)
I was staring at the original diff in gmail trying to figure out what
I was looking at, and this should be equivalent to your patch but
spare the eyes of future generations slightly (this is directed at the
original code, not your patch),
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 8b5955819a..0fed297b56 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -612,9 +612,10 @@ instmatch(Cmatch m, int *scs)
int pcs = zlemetacs;
l = 0;
- for (bp = brbeg, brpos = m->brpl,
- bradd = (m->pre ? strlen(m->pre) : 0);
- bp; bp = bp->next, brpos++) {
+ bradd = (m->pre ? strlen(m->pre) : 0);
+ for (bp = brbeg, brpos = m->brpl;
+ bp && brpos;
+ bp = bp->next, brpos++) {
zlemetacs = a + *brpos + bradd;
pcs = zlemetacs;
l = strlen(bp->str);
Eg, bradd is not involved with the loop condition at all, so don't set
it in the for-initializer, and put each foo;bar;baz; on separate
lines.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author