Re: [Outreachy PATCH v4 2/2] gpg-interface: do not use misdesigned strbuf_split*() [Part 2]
- From
Bello Olamide <belkid98@gmail.com>
- Date
- Oct 21, 2025, 12:12 UTC
- Message-ID
- <CAD=f0L9sn_D437PM1LQdaY=nGCtEe0yg3Nq7_d6-yupE9pMMZg@mail.gmail.com>
- In-Reply-To
- <CAP8UFD1-H5jRyd6b5FhgCMLObnErXVr8p0s+kMd0qO5jWkkt2Q@mail.gmail.com>
On Tue, 21 Oct 2025 at 08:01, Christian Couder <christian.couder@gmail.com> wrote:
Show 14 quoted lines
> > On Tue, Oct 21, 2025 at 12:57 AM Olamide Caleb Bello <belkid98@gmail.com> wrote: > > [...] > > > Reported-by: Junio Hamano <gitster@pobox.com> > > Helped-by: Christian Couder <christian.couder@gmail.com> > > Helped-by: Junio Hamano <gitster@pobox.com> > > Helped-by: Krisoffer Haughsbakk > > I won't repeat the issues that are the same as in patch 1/2, but > please correct them. > > [...]
Yes, thank you.
I will fix them.
Show 12 quoted lines
>
> > @@ -887,19 +887,21 @@ static char *get_default_ssh_signing_key(void)
> > &key_stderr, 0);
> >
> > if (!ret) {
> > - keys = strbuf_split_max(&key_stdout, '\n', 2);
> > - if (keys[0] && is_literal_ssh_key(keys[0]->buf, &literal_key)) {
> > + begin = key_stdout.buf;
> > + new_line = strchr(begin, '\n');
> > + first_line = xmemdupz(begin, new_line - begin);
>
> What if no \n character is found by strchr()?In the original code, just the first line of a possible two lines
is returned.
So since we need just the first and if no new line is found,
I can do
char *end = new_line ? new_line : strchr(begin, '\0');
first_line = xmemdupz(begin, end);Does this work?
Thanks Bello