]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Add format attribute and fix issues
authorLucas De Marchi <lucas.de.marchi@gmail.com>
Sun, 21 Apr 2013 19:16:18 +0000 (16:16 -0300)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Sun, 21 Apr 2013 19:17:12 +0000 (16:17 -0300)
Add __attribute__((format)) to log_filep() and _show() functions, fixing
the bugs they found in the source code.

For functions that receive va_list instead of being variadic functions
we put 0 in the last argument, so at least the string is checked and we
get warnings of -Wformat-nonliteral type. So, it's better than adding a
pragma here to shut up the warning.

libkmod/libkmod.c
tools/depmod.c
tools/log.c
tools/log.h
tools/modprobe.c

index 2ef19d3f6d46e4460bd77b203628d81a554f6a27..66d48594120285a79ed9758849779395f5dd933e 100644 (file)
@@ -99,6 +99,7 @@ void kmod_log(const struct kmod_ctx *ctx,
        va_end(args);
 }
 
+_printf_format_(6, 0)
 static void log_filep(void *data,
                        int priority, const char *file, int line,
                        const char *fn, const char *format, va_list args)
index ec00921d4937bfa4644f6b2b388fb160cc9a9dba..4a02631330ce780ff811f35163b1de8bdf248bb9 100644 (file)
@@ -101,6 +101,7 @@ static void help(void)
                program_invocation_short_name);
 }
 
+_printf_format_(1, 2)
 static inline void _show(const char *fmt, ...)
 {
        va_list args;
@@ -1256,7 +1257,7 @@ static int depmod_modules_search_dir(struct depmod *depmod, DIR *d, size_t basel
                namelen = strlen(name);
                if (baselen + namelen + 2 >= PATH_MAX) {
                        path[baselen] = '\0';
-                       ERR("path is too long %s%s %zd\n", path, name);
+                       ERR("path is too long %s%s\n", path, name);
                        continue;
                }
                memcpy(path + baselen, name, namelen + 1);
@@ -1504,7 +1505,7 @@ load_info:
                mod->kmod = NULL;
        }
 
-       DBG("loaded symbols (%zd modules, %zd symbols)\n",
+       DBG("loaded symbols (%zd modules, %u symbols)\n",
            depmod->modules.count, hash_get_count(depmod->symbols));
 
        return 0;
@@ -1550,7 +1551,7 @@ static int depmod_load_dependencies(struct depmod *depmod)
 {
        struct mod **itr, **itr_end;
 
-       DBG("load dependencies (%zd modules, %zd symbols)\n",
+       DBG("load dependencies (%zd modules, %u symbols)\n",
            depmod->modules.count, hash_get_count(depmod->symbols));
 
        itr = (struct mod **)depmod->modules.array;
@@ -1566,7 +1567,7 @@ static int depmod_load_dependencies(struct depmod *depmod)
                depmod_load_module_dependencies(depmod, mod);
        }
 
-       DBG("loaded dependencies (%zd modules, %zd symbols)\n",
+       DBG("loaded dependencies (%zd modules, %u symbols)\n",
            depmod->modules.count, hash_get_count(depmod->symbols));
 
        return 0;
@@ -1609,7 +1610,7 @@ static int depmod_calculate_dependencies(struct depmod *depmod)
        roots = users + n_mods;
        sorted = roots + n_mods;
 
-       DBG("calculate dependencies and ordering (%zd modules)\n", n_mods);
+       DBG("calculate dependencies and ordering (%hu modules)\n", n_mods);
 
        assert(depmod->modules.count < UINT16_MAX);
 
@@ -1650,7 +1651,7 @@ static int depmod_calculate_dependencies(struct depmod *depmod)
        }
 
        if (n_sorted < n_mods) {
-               WRN("found %hu modules in dependency cycles!\n",
+               WRN("found %u modules in dependency cycles!\n",
                    n_mods - n_sorted);
                for (i = 0; i < n_mods; i++) {
                        struct mod *m;
@@ -1666,7 +1667,7 @@ static int depmod_calculate_dependencies(struct depmod *depmod)
 
        depmod_sort_dependencies(depmod);
 
-       DBG("calculated dependencies and ordering (%u loops, %zd modules)\n",
+       DBG("calculated dependencies and ordering (%u loops, %hu modules)\n",
            depmod->dep_loops, n_mods);
 
        free(users);
@@ -2356,7 +2357,7 @@ static int depfile_up_to_date_dir(DIR *d, time_t mtime, size_t baselen, char *pa
                namelen = strlen(name);
                if (baselen + namelen + 2 >= PATH_MAX) {
                        path[baselen] = '\0';
-                       ERR("path is too long %s%s %zd\n", path, name);
+                       ERR("path is too long %s%s\n", path, name);
                        continue;
                }
 
index 21ef305a9651c96ac716201349159d8982bf5bd6..05f6b7741059b7accdc40aba3efb1c5d1e4c7fdd 100644 (file)
@@ -60,6 +60,7 @@ static _always_inline_ const char *prio_to_str(int prio)
        return prioname;
 }
 
+_printf_format_(6, 0)
 static void log_kmod(void *data, int priority, const char *file, int line,
                     const char *fn, const char *format, va_list args)
 {
index bc4b150f08f0c2cd336ddd6d055d0ad63d6e73d1..d55a4c6fd1c3f27f14db01ba32bfa7fc4653eb47 100644 (file)
@@ -26,7 +26,7 @@
 
 void log_open(bool use_syslog);
 void log_close(void);
-void log_printf(int prio, const char *fmt, ...);
+void log_printf(int prio, const char *fmt, ...) _printf_format_(2, 3);
 #define CRIT(...) log_printf(LOG_CRIT, __VA_ARGS__)
 #define ERR(...) log_printf(LOG_ERR, __VA_ARGS__)
 #define WRN(...) log_printf(LOG_WARNING, __VA_ARGS__)
index 1b8c96e6d93f7960b4fa08d3d870995e2efd1e2a..a053efb7576d60e19fbb4838d4a0c5aa7904a463 100644 (file)
@@ -142,6 +142,7 @@ static void help(void)
                program_invocation_short_name, program_invocation_short_name);
 }
 
+_printf_format_(1, 2)
 static inline void _show(const char *fmt, ...)
 {
        va_list args;