From: Stefan Beller <sbeller@google.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, git <git@vger.kernel.org>,
Han-Wen Nienhuys <hanwen@google.com>
Subject: Re: [PATCH] sideband: color lines with keyword only
Date: Mon, 3 Dec 2018 15:35:28 -0800 [thread overview]
Message-ID: <CAGZ79kY0w7Zt0Z4KNu7qL4Lz8fFpv2p51D-w_MgZBYPqPFbZKw@mail.gmail.com> (raw)
In-Reply-To: <20181203232353.GA157301@google.com>
On Mon, Dec 3, 2018 at 3:23 PM Jonathan Nieder <jrnieder@gmail.com> wrote:
> I was curious about what versions of Gerrit this is designed to
> support (or in other words whether it's a bug fix or a feature).
> Looking at examples like [1], it seems that Gerrit historically always
> used "ERROR:" so the 59a255aef0 logic would work for it. More
> recently, [2] (ReceiveCommits: add a "SUCCESS" marker for successful
> change updates, 2018-08-21) put SUCCESS on a line of its own. That
> puts this squarely in the new-feature category.
Ooops. From the internal bug, I assumed this to be long standing Gerrit
behavior, which is why I sent it out in -rc to begin with.
> > --- a/sideband.c
> > +++ b/sideband.c
> > @@ -87,7 +87,7 @@ static void maybe_colorize_sideband(struct strbuf *dest, const char *src, int n)
> > struct keyword_entry *p = keywords + i;
> > int len = strlen(p->keyword);
> >
> > - if (n <= len)
> > + if (n < len)
> > continue;
>
> In the old code, we would escape early if 'n == len', but we didn't
> need to. If 'n == len', then
>
> src[len] == '\0'
src[len] could also be one of "\n\r", see the caller
recv_sideband for sidebase case 2.
> src .. &src[len-1] is a valid buffer to read from
>
> so the strncasecmp and strbuf_add operations used in this function are
> valid. Good.
Yes, they are all valid...
> > - if (!strncasecmp(p->keyword, src, len) && !isalnum(src[len])) {
> > + if (!strncasecmp(p->keyword, src, len) &&
> > + (len == n || !isalnum(src[len]))) {
>
> Our custom isalnum treats '\0' as not alphanumeric (sane_ctype[0] ==
> GIT_CNTRL) so this part of the patch is unnecessary. That said, it's
> good for clarity and defensive programming.
... but here we need to check for src[len] for validity.
I made no assumptions about isalnum, but rather needed to shortcut
the condition, as accessing src[len] would be out of bounds, no?
>
> > strbuf_addstr(dest, p->color);
> > strbuf_add(dest, src, len);
unlike here (or the rest of the block), where len is used correctly.
next prev parent reply other threads:[~2018-12-03 23:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-03 22:37 [PATCH] sideband: color lines with keyword only Stefan Beller
2018-12-03 23:23 ` Jonathan Nieder
2018-12-03 23:34 ` Jonathan Nieder
2018-12-03 23:35 ` Stefan Beller [this message]
2018-12-03 23:42 ` Jonathan Nieder
2018-12-04 3:16 ` Junio C Hamano
2018-12-10 11:03 ` Han-Wen Nienhuys
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGZ79kY0w7Zt0Z4KNu7qL4Lz8fFpv2p51D-w_MgZBYPqPFbZKw@mail.gmail.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hanwen@google.com \
--cc=jrnieder@gmail.com \
/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://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).