<div dir="ltr">That's not actually correct in practice. If you'd like to see that I'm correct take the following two programs:<div><br></div><div>foo.c:</div><div><div>#include <string.h></div><div>#include <stdio.h></div><div><br></div><div>int main(int argc, char *argv[]) {</div><div> if (strlen(argv[0]) == 0) {</div><div> printf("Command empty");</div><div> } else {</div><div> printf("Command not empty");</div><div> }</div><div>}</div><div>bar.c:</div><div>#include <string.h></div><div>#include <stdio.h></div><div><br></div><div>int main(int argc, char *argv[]) {</div><div> if (*argv[0] == '\0') {</div><div> printf("Command empty");</div><div> } else {</div><div> printf("Command not empty");</div><div> }</div><div>}</div></div><div><br></div><div>Next compile them to assembly like so:</div><div><br></div><div>for f in {foo,bar}.c; do gcc -O2 -S $f; done</div><div><br></div><div>And then compare them:</div><div><br></div><div>diff {foo,bar}.s</div><div><br></div><div>They should be the same (possibly different by a ".file" line). And if you inspect the resulting code, there won't be a call to strlen or to any function at all (well, except printf).</div><div><br></div><div>The reason is that gcc, like most C compilers since the 90s, optimises a number of common functions in the standard C library. Which means that developers can stick with writing code that will be well-optimised *and* highly readable.</div><div><br></div><div>Kevin</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Oct 5, 2017 at 8:31 PM Roy Marples <<a href="mailto:roy@marples.name">roy@marples.name</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 05/10/2017 03:23, Rosen Penev wrote:<br>
> @@ -1239,7 +1238,7 @@ static struct serverfd *allocate_sfd(union mysockaddr *addr, char *intname)<br>
> #endif<br>
> }<br>
><br>
> - if (intname && strlen(intname) != 0)<br>
> + if (!strlen(intname))<br>
> ifindex = if_nametoindex(intname); /* index == 0 when not binding to an interface */<br>
><br>
> /* may have a suitable one already */<br>
><br>
<br>
I have no comment on the functionality of the patch (it if intname needs<br>
to be NULL checked or not), but this is not a good use of strlen.<br>
<br>
This could be re-written as<br>
<br>
if (*intname != '\0')<br>
<br>
Which saves a function call because the actual length of the string is<br>
not used.<br>
<br>
Roy<br>
<br>
_______________________________________________<br>
Dnsmasq-discuss mailing list<br>
<a href="mailto:Dnsmasq-discuss@lists.thekelleys.org.uk" target="_blank">Dnsmasq-discuss@lists.thekelleys.org.uk</a><br>
<a href="http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss" rel="noreferrer" target="_blank">http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss</a><br>
</blockquote></div>