[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kvm
Subject:    Re: [PATCH kvm-unit-tests 1/3] lib/string: Fix getenv name matching
From:       Paolo Bonzini <pbonzini () redhat ! com>
Date:       2020-10-31 14:31:07
Message-ID: 7ffb378d-74eb-c92a-d4f4-510409f2c059 () redhat ! com
[Download RAW message or body]

On 14/10/20 21:14, Andrew Jones wrote:
> +        if (strlen(name) == len && strncmp(name, *envp, len) == 0)
>              return delim + 1;
>          ++envp;
>      }
> -- 2.26.2


Slightly more efficient:

+        if (memcmp(name, *envp, len) == 0 && !name[len])

(strncmp is not needed since we know there's no NULL between *envp and
*envp+len, and after memcmp we know the same about the first len
characters of name).

Paolo

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic