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

Re: [libvirt] [PATCH] Blank out invalid interface names with escaped letters etc.



On 03/31/2010 07:20 AM, Daniel P. Berrange wrote:
> There's a slightly simpler way you can do this using strspn avoiding the
> regex engine
> 
>  #define VALID_IFNAME_CHARS
>   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
> 
>  rc = strspn(ifname, VALID_IFNAME_CHARS) != strlen (value);

That scans the string twice; if ifname is arbitrarily long, this can be
inefficient.  As a micro-optimization, you could instead check:

rc = !ifname[strspn(ifname, VALID_IFNAME_CHARS)];

-- 
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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