bug-make
[Top][All Lists]
Advanced

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

Re: Segmentation Fault on Exported Resursively Expanded Variable


From: Henrik Carlqvist
Subject: Re: Segmentation Fault on Exported Resursively Expanded Variable
Date: Sun, 21 Jan 2024 22:14:09 +0100

On Sun, 21 Jan 2024 14:45:00 -0500
Dmitry Goncharov <dgoncharov@users.sf.net> wrote:
> 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.

Yes, that is also my guess. Unfortunately, it could give a segfault if
(*ep)[nl] is not a valid memory location.

> 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.

I haven't done any measurements either, but my guess is that strlen is faster
for the cases when the strlen(*ep) is shorter than about double the position
of the first different characters in *ep and v->name. So strncmp might be
faster if the strings differ in the beginning as strncmp probably will abort
at the first difference but strlen will not abort until the end of the string.
But on the other hand, strlen will be at least twice as fast for every 
position as it only cares about a single string and does not care about any
max length. 

regards Henrik



reply via email to

[Prev in Thread] Current Thread [Next in Thread]