Subject: Re: [RFC PATCH 5/6] ls-tree: introduce 'match_pattern()' function

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Wed, 30 Nov 2022 10:39:07 +0100

On Thu, Nov 17 2022, Teng Long wrote:

(I saw this in the latest "seen" push-out)

> From: Teng Long <[email-masked]>
> [...]
> +__attribute__((unused))
> +static int match_pattern(const char *line)
> +{
> +	int ret = 0;
> +	regex_t r;
> +	regmatch_t m[1];

Here we hardcode the size of "m".

(Re-arranged a bit)

> +
> +	ret = regcomp(&r, pattern, 0);
> +	if (ret) {
> +		regerror(ret, &r, errbuf, sizeof(errbuf));
> +		die("failed regcomp() for pattern '%s' (%s)", pattern, errbuf);

Needs _().

> +	}
> +	ret = regexec(&r, line, 1, m, 0);

Here we hardcode that "1" again, but we should use ARRAY_SIZE()
instead. See an existing example at:

	git grep -W regexec.*ARRAY

(Re-arranged from above)

> +	char errbuf[64];

This is a super short errbuf, in other cases we hardcode this to 1024,
which seems reasonable.