diff options
author | Josh Triplett <josh@joshtriplett.org> | 2014-03-15 11:40:07 -0700 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-03-16 09:52:56 -0400 |
commit | f8294e4175918117ca6c131720bcf287eadcd029 (patch) | |
tree | c5b2f4d3088fbd4fd75989b3f7eed128681951e1 /src/core | |
parent | 039dd4afd64a8c8413ff28d43f533c30c5a06a16 (diff) |
Use strlen even for constant strings
GCC optimizes strlen("string constant") to a constant, even with -O0.
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.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/dbus.c | 2 | ||||
-rw-r--r-- | src/core/service.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/src/core/dbus.c b/src/core/dbus.c index 03f3738abc..72f36bdc1c 100644 --- a/src/core/dbus.c +++ b/src/core/dbus.c @@ -953,7 +953,7 @@ static int bus_init_private(Manager *m) { return 0; strcpy(sa.un.sun_path, "/run/systemd/private"); - salen = offsetof(union sockaddr_union, un.sun_path) + sizeof("/run/systemd/private") - 1; + salen = offsetof(union sockaddr_union, un.sun_path) + strlen("/run/systemd/private"); } else { size_t left = sizeof(sa.un.sun_path); char *p = sa.un.sun_path; diff --git a/src/core/service.c b/src/core/service.c index 121ddec6ad..41b95ab0f3 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -361,7 +361,7 @@ static int service_arm_timer(Service *s, usec_t usec) { static char *sysv_translate_name(const char *name) { char *r; - r = new(char, strlen(name) + sizeof(".service")); + r = new(char, strlen(name) + strlen(".service") + 1); if (!r) return NULL; |