On Tue, Jan 16, 2024 at 1:21 PM Henrik Carlqvist <hc...@poolhem.se> wrote:
>
> On Tue, 16 Jan 2024 06:59:30 +0000
> MIAOW Miao <guoyr_2...@hotmail.com> wrote:
> > if ((*ep)[nl] == '=' && strncmp (*ep, v->name, nl) == 0)
>
> Looking at that line, the rather obvious fix would be to change it to:
>
> if (strncmp (*ep, v->name, nl) == 0 && (*ep)[nl] == '=')


i bet, the purpose of having (*ep)[nl] == '=' check before strncmp was
to relieve make from running strncmp unless the variables have the
same length.
Similarly, the fix attached to the savannah report
         size_t len = strlen (*ep);
         if (len >= nl && (*ep)[nl] == '=' && memcmp (*ep, v->name, nl) == 0)

does the length check before memcmp for the same purpose, to relieve
make from running memcmp, unless needed.

For every char, strncmp does two checks, n and the character. strlen
does only one check.
Without doing any measurements, i expect, strlen do better than
strncmp when strlen (*ep) is shorter than nl.
On the other hand, when v->name is half the length of *ep, we'd prefer strncmp.

regards, Dmitry

Reply via email to