summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.de.marchi@gmail.com>2013-04-21 16:16:18 -0300
committerLucas De Marchi <lucas.de.marchi@gmail.com>2013-04-21 16:17:12 -0300
commit1958af88a2078970cc0b4281cdfef16fe54071b6 (patch)
tree28ed9b758760991606655ed0e1f52ae392afc6bd
parent19ac5bd8a00395945a4e34d12ea756d744cce909 (diff)
downloadkmod-1958af88a2078970cc0b4281cdfef16fe54071b6.tar.gz
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.
-rw-r--r--libkmod/libkmod.c1
-rw-r--r--tools/depmod.c17
-rw-r--r--tools/log.c1
-rw-r--r--tools/log.h2
-rw-r--r--tools/modprobe.c1
5 files changed, 13 insertions, 9 deletions
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 2ef19d3..66d4859 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 ec00921..4a02631 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 21ef305..05f6b77 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 bc4b150..d55a4c6 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 1b8c96e..a053efb 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;