From: Lucas De Marchi Date: Sun, 21 Apr 2013 19:16:18 +0000 (-0300) Subject: Add format attribute and fix issues X-Git-Tag: v14~17 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=1958af88a2078970cc0b4281cdfef16fe54071b6;p=thirdparty%2Fkmod.git Add format attribute and fix issues 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. --- diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 2ef19d3f..66d48594 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -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) diff --git a/tools/depmod.c b/tools/depmod.c index ec00921d..4a026313 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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; } diff --git a/tools/log.c b/tools/log.c index 21ef305a..05f6b774 100644 --- a/tools/log.c +++ b/tools/log.c @@ -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) { diff --git a/tools/log.h b/tools/log.h index bc4b150f..d55a4c6f 100644 --- a/tools/log.h +++ b/tools/log.h @@ -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__) diff --git a/tools/modprobe.c b/tools/modprobe.c index 1b8c96e6..a053efb7 100644 --- a/tools/modprobe.c +++ b/tools/modprobe.c @@ -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;