From: Emil Velikov Date: Sat, 24 May 2025 11:06:13 +0000 (+0100) Subject: tools: use strlen() for string literals X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b116d8a6e3388ad45845965f7317ba336d30909;p=thirdparty%2Fkmod.git tools: use strlen() for string literals Older compilers had struggles expanding strlen(string-literal) to a constant compile time expression. Thus our code-base used sizeof() - 1 instead. This has been resolved for years, so let's use the correct function. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/354 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index 6d03fbab..f9faecba 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -2529,7 +2529,7 @@ static int output_devname(struct depmod *depmod, FILE *out) unsigned int maj, min; if (strstartswith(value, "devname:")) - devname = value + sizeof("devname:") - 1; + devname = value + strlen("devname:"); else if (sscanf(value, "char-major-%u-%u", &maj, &min) == 2) { type = 'c'; major = maj; diff --git a/tools/modprobe.c b/tools/modprobe.c index a58b8ef1..a32ccfba 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -273,7 +273,7 @@ static int command_do(struct kmod_module *module, const char *type, const char * if (cmd == NULL) return -ENOMEM; cmdlen = strlen(cmd); - varlen = sizeof("$CMDLINE_OPTS") - 1; + varlen = strlen("$CMDLINE_OPTS"); while ((p = strstr(cmd, "$CMDLINE_OPTS")) != NULL) { size_t prefixlen = p - cmd; size_t suffixlen = cmdlen - prefixlen - varlen;