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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 17 2022, Teng Long wrote:

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

> From: Teng Long <dyroneteng@xxxxxxxxx>
> [...]
> +__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.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux