Skip to content

Commit

Permalink
libkmod: _printf_format_ annotate and adjust ELFDBG modifiers
Browse files Browse the repository at this point in the history
The recently added "always build ELFDBG" patch is already paying
dividends... Clang is flagging a "fmt" is not literal warning.

That's clearly wrong, although without _printf_format_ clang was
struggling to figure things out. With the attribute, it helpfully
flagged that handful of the modifiers are wrong.

Signed-off-by: Emil Velikov <[email protected]>
Link: #172
Signed-off-by: Lucas De Marchi <[email protected]>
  • Loading branch information
evelikov authored and lucasdemarchi committed Oct 18, 2024
1 parent e16d92b commit d567219
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions libkmod/libkmod-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ struct kmod_elf {
_elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__); \
} while (0);

static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line,
const char *func, const char *fmt, ...)
_printf_format_(5, 6) static inline void _elf_dbg(const struct kmod_elf *elf,
const char *fname, unsigned line,
const char *func, const char *fmt, ...)
{
va_list args;

Expand Down Expand Up @@ -150,14 +151,14 @@ static inline int elf_set_uint(const struct kmod_elf *elf, uint64_t offset, uint
size_t i;

ELFDBG(elf,
"size=%" PRIu16 " offset=%" PRIu64 " value=%" PRIu64 " write memory=%p\n",
"size=%" PRIu64 " offset=%" PRIu64 " value=%" PRIu64 " write memory=%p\n",
size, offset, value, changed);

assert(size <= sizeof(uint64_t));
assert(offset + size <= elf->size);
if (offset + size > elf->size) {
ELFDBG(elf,
"out of bounds: %" PRIu64 " + %" PRIu16 " = %" PRIu64 "> %" PRIu64
"out of bounds: %" PRIu64 " + %" PRIu64 " = %" PRIu64 "> %" PRIu64
" (ELF size)\n",
offset, size, offset + size, elf->size);
return -1;
Expand Down Expand Up @@ -313,9 +314,7 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size)
elf->header.section.entry_size, elf->header.strings.section);

if (elf->header.section.entry_size != shdr_size) {
ELFDBG(elf,
"unexpected section entry size: %" PRIu16 ", expected %" PRIu16
"\n",
ELFDBG(elf, "unexpected section entry size: %" PRIu16 ", expected %zu\n",
elf->header.section.entry_size, shdr_size);
goto invalid;
}
Expand Down Expand Up @@ -1105,7 +1104,7 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf,

name = elf_get_mem(elf, str_off + name_off);
if (name[0] == '\0') {
ELFDBG(elf, "empty symbol name at index %" PRIu64 "\n", i);
ELFDBG(elf, "empty symbol name at index %d\n", i);
continue;
}

Expand Down Expand Up @@ -1192,7 +1191,7 @@ int kmod_elf_get_dependency_symbols(const struct kmod_elf *elf,

name = elf_get_mem(elf, str_off + name_off);
if (name[0] == '\0') {
ELFDBG(elf, "empty symbol name at index %" PRIu64 "\n", i);
ELFDBG(elf, "empty symbol name at index %d\n", i);
continue;
}

Expand Down

0 comments on commit d567219

Please sign in to comment.