All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] mailinfo: we parse fixed headers
Date: Thu, 22 Aug 2024 10:24:12 +0200	[thread overview]
Message-ID: <Zsb1rGQbglHMiBHI@tanuki> (raw)
In-Reply-To: <xmqq1q2i6gw7.fsf@gitster.g>

On Tue, Aug 20, 2024 at 02:09:12PM -0700, Junio C Hamano wrote:
> diff --git c/mailinfo.c w/mailinfo.c
> index 94b9b0abf2..17d7c3b594 100644
> --- c/mailinfo.c
> +++ w/mailinfo.c
> @@ -346,10 +346,10 @@ static void cleanup_subject(struct mailinfo *mi, struct strbuf *subject)
>  	strbuf_trim(subject);
>  }
>  
> -#define MAX_HDR_PARSED 10
> -static const char *header[MAX_HDR_PARSED] = {
> -	"From","Subject","Date",
> +static const char * const header[] = {
> +	"From", "Subject", "Date",
>  };
> +#define MAX_HDR_PARSED (ARRAY_SIZE(header) + 1)
>  
>  static inline int skip_header(const struct strbuf *line, const char *hdr,
>  			      const char **outval)

I was briefly wondering whether changing MAX_HDR_PARSED is going to
cause negative fallout. But the only place where it is used is to
allocate both the `mi->p_hdr_data` and `mi->s_hdr_data` arrays. And
these are only populated via non-NULL `header`s.

> @@ -583,7 +583,7 @@ static int check_header(struct mailinfo *mi,
>  	struct strbuf sb = STRBUF_INIT;
>  
>  	/* search for the interesting parts */
> -	for (i = 0; header[i]; i++) {
> +	for (i = 0; i < ARRAY_SIZE(header); i++) {
>  		if ((!hdr_data[i] || overwrite) &&
>  		    parse_header(line, header[i], mi, &sb)) {
>  			handle_header(&hdr_data[i], &sb);

This is also a welcome change, as it makes it way easier to spot intent
and to notice that `header` is indeed a static array of string
constants.

So this change looks sensible to me, thanks!

Patrick

      reply	other threads:[~2024-08-22  8:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-20 21:09 [PATCH] mailinfo: we parse fixed headers Junio C Hamano
2024-08-22  8:24 ` Patrick Steinhardt [this message]

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=Zsb1rGQbglHMiBHI@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.