]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools: use strlen() for string literals
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 24 May 2025 11:06:13 +0000 (12:06 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 29 May 2025 22:10:16 +0000 (17:10 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/354
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/depmod.c
tools/modprobe.c

index 6d03fbab0ed5ee9771239fd6ebcce839d92688e2..f9faecba0ff33f71266108394eea455dbf887e20 100644 (file)
@@ -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;
index a58b8ef176ee17b8c813c4f2c7ebb83a2cfad3dc..a32ccfbaac9b512a945d8c87768dc317820c9c64 100644 (file)
@@ -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;