[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Segmentation Fault on Exported Resursively Expanded Variable
From: |
Dmitry Goncharov |
Subject: |
Re: Segmentation Fault on Exported Resursively Expanded Variable |
Date: |
Sun, 21 Jan 2024 14:45:00 -0500 |
On Tue, Jan 16, 2024 at 1:21 PM Henrik Carlqvist <hc981@poolhem.se> wrote:
>
> On Tue, 16 Jan 2024 06:59:30 +0000
> MIAOW Miao <guoyr_2013@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
- Segmentation Fault on Exported Resursively Expanded Variable, MIAOW Miao, 2024/01/15
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Paul Smith, 2024/01/15
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Henrik Carlqvist, 2024/01/15
- Re: Re: Segmentation Fault on Exported Resursively Expanded Variable, MIAOW Miao, 2024/01/16
- Re: Re: Segmentation Fault on Exported Resursively Expanded Variable, Paul Smith, 2024/01/16
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Henrik Carlqvist, 2024/01/16
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Eli Zaretskii, 2024/01/16
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Henrik Carlqvist, 2024/01/17
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Edward Welbourne, 2024/01/17
- Re: Segmentation Fault on Exported Resursively Expanded Variable,
Dmitry Goncharov <=
- Re: Segmentation Fault on Exported Resursively Expanded Variable, Henrik Carlqvist, 2024/01/21
Re: Segmentation Fault on Exported Resursively Expanded Variable, Dmitry Goncharov, 2024/01/15
Re: Segmentation Fault on Exported Resursively Expanded Variable, Dmitry Goncharov, 2024/01/16