mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-11-23 23:10:53 +07:00
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.
This commit is contained in:
parent
19ac5bd8a0
commit
1958af88a2
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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__)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user