[Dnsmasq-discuss] [PATCH] Remove NULL check for intname.

Roy Marples roy at marples.name
Thu Oct 5 19:49:03 BST 2017


On 05/10/2017 03:23, Rosen Penev wrote:
> @@ -1239,7 +1238,7 @@ static struct serverfd *allocate_sfd(union mysockaddr *addr, char *intname)
>   #endif
>       }
>   
> -  if (intname && strlen(intname) != 0)
> +  if (!strlen(intname))
>       ifindex = if_nametoindex(intname); /* index == 0 when not binding to an interface */
>   
>     /* may have a suitable one already */
> 

I have no comment on the functionality of the patch (it if intname needs 
to be NULL checked or not), but this is not a good use of strlen.

This could be re-written as

if (*intname != '\0')

Which saves a function call because the actual length of the string is 
not used.

Roy



More information about the Dnsmasq-discuss mailing list