[systemd-devel] [PATCH] Use strlen even for constant strings

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Fri Mar 14 21:37:49 PDT 2014


On Sat, Mar 08, 2014 at 10:54:36PM -0800, Josh Triplett wrote:
> GCC optimizes strlen("string constant") to a constant, even with -O0.
(clang does too, btw).

> Thus, replace patterns like sizeof("string constant")-1 with
> strlen("string constant") where possible, for clarity.  In particular,
> for expressions intended to add up the lengths of components going into
> a string, this often makes it clearer that the expression counts the
> trailing '\0' exactly once, by putting the +1 for the '\0' at the end of
> the expression, rather than hidden in a sizeof in the middle of the
> expression.
strlen() is indeed much nicer. Unfortunately it stopped applying cleanly...
Could you rebase this? 

Zbyszek


More information about the systemd-devel mailing list