From: Ævar Arnfjörð Bjarmason Date: Wed, 30 Nov 2022 09:39:07 GMT Subject: Re: [RFC PATCH 5/6] ls-tree: introduce 'match_pattern()' function Message-ID: <221130.86pmd4ixqj.gmgdl@evledraar.gmail.com> In-Reply-To: <20221117113023.65865-6-tenglong.tl@alibaba-inc.com> On Thu, Nov 17 2022, Teng Long wrote: (I saw this in the latest "seen" push-out) > From: Teng Long > [...] > +__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.