summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2014-03-15 11:40:07 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-03-16 09:52:56 -0400
commitf8294e4175918117ca6c131720bcf287eadcd029 (patch)
treec5b2f4d3088fbd4fd75989b3f7eed128681951e1 /src/shared/util.c
parent039dd4afd64a8c8413ff28d43f533c30c5a06a16 (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/shared/util.c')
-rw-r--r--src/shared/util.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 7e17851fcd..75870fcbe2 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4185,7 +4185,7 @@ int socket_from_display(const char *display, char **path) {
k = strspn(display+1, "0123456789");
- f = new(char, sizeof("/tmp/.X11-unix/X") + k);
+ f = new(char, strlen("/tmp/.X11-unix/X") + k + 1);
if (!f)
return -ENOMEM;