From ca3b221b96a4d621c75f1e62aea74d6d83cadcd8 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Wed, 24 Jun 2020 01:49:27 +0200 Subject: Add STRLEN constant macro --- minecproxy/idle.c | 2 +- minecproxy/server.c | 2 +- minecproxy/systemd.c | 6 +++--- minecproxy/uring.c | 2 +- shared/utils.h | 10 ++++++---- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/minecproxy/idle.c b/minecproxy/idle.c index 90d7210..8fcb934 100644 --- a/minecproxy/idle.c +++ b/minecproxy/idle.c @@ -167,7 +167,7 @@ get_player_count(const char *pos, size_t remain) assert_return(pos && remain > 0, -1); - online = memmem(pos, remain, ONLINE_NEEDLE, strlen(ONLINE_NEEDLE)); + online = memmem(pos, remain, ONLINE_NEEDLE, STRLEN(ONLINE_NEEDLE)); if (!online) { error("could not find online count in JSON"); return -1; diff --git a/minecproxy/server.c b/minecproxy/server.c index c6e6480..c1480f3 100644 --- a/minecproxy/server.c +++ b/minecproxy/server.c @@ -684,7 +684,7 @@ server_set_systemd_service(struct server *server, const char *service) suffix = strrchr(service, '.'); if (!suffix || !streq(suffix, ".service")) { - tmp = zmalloc(strlen(service) + strlen(".service") + 1); + tmp = zmalloc(strlen(service) + STRLEN(".service") + 1); if (tmp) sprintf(tmp, "%s.service", service); } else diff --git a/minecproxy/systemd.c b/minecproxy/systemd.c index a44b0d8..e9ed885 100644 --- a/minecproxy/systemd.c +++ b/minecproxy/systemd.c @@ -38,12 +38,12 @@ systemd_object_path(const char *service) assert_return(service && !empty_str(service), NULL); - r = zmalloc(strlen(SYSTEMD_DBUS_PATH_PREFIX) + strlen(service) * 3 + 1); + r = zmalloc(STRLEN(SYSTEMD_DBUS_PATH_PREFIX) + strlen(service) * 3 + 1); if (!r) return NULL; - memcpy(r, SYSTEMD_DBUS_PATH_PREFIX, strlen(SYSTEMD_DBUS_PATH_PREFIX)); - d = r + strlen(SYSTEMD_DBUS_PATH_PREFIX); + memcpy(r, SYSTEMD_DBUS_PATH_PREFIX, STRLEN(SYSTEMD_DBUS_PATH_PREFIX)); + d = r + STRLEN(SYSTEMD_DBUS_PATH_PREFIX); for (s = service; *s; s++) { if ((*s >= 'a' && *s <= 'z') || diff --git a/minecproxy/uring.c b/minecproxy/uring.c index 79b90b8..abea592 100644 --- a/minecproxy/uring.c +++ b/minecproxy/uring.c @@ -68,7 +68,7 @@ uring_task_refdump(struct uring_task *task) char *dst; if (tmp->parent) - prefix = strlen("->") + strlen(tmp->name); + prefix = STRLEN("->") + strlen(tmp->name); else prefix = strlen(tmp->name); diff --git a/shared/utils.h b/shared/utils.h index 0fc1429..d0142b1 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -34,6 +34,8 @@ extern unsigned debug_mask; #endif #endif +#define STRLEN(x) (sizeof(""x"") - 1) + #include "list.h" #include "debug.h" #include "external.h" @@ -41,11 +43,11 @@ extern unsigned debug_mask; /* Length of longest DNS name = 253 + trailing dot */ #define FQDN_STR_LEN 254 -/* Length of longest port string = strlen("65535") */ -#define PORT_STR_LEN 5 +/* Length of longest port string */ +#define PORT_STR_LEN STRLEN("65535") -/* Length of longest address family string = strlen("AF_INETX") */ -#define AF_STR_LEN 8 +/* Length of longest address family string */ +#define AF_STR_LEN STRLEN("AF_INETX") /* Length of longest addrstr, format = "AF_INETX */ #define ADDRSTRLEN (AF_STR_LEN + 1 + INET6_ADDRSTRLEN + 1 + PORT_STR_LEN + 1) -- cgit v1.2.3