]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: _printf_format_ annotate and adjust ELFDBG modifiers
authorEmil Velikov <emil.l.velikov@gmail.com>
Thu, 17 Oct 2024 18:17:25 +0000 (19:17 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 18 Oct 2024 18:22:11 +0000 (13:22 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/172
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-elf.c

index d381e36504de08bc7c696efe03695fe6cb48c1e9..c62bd0d849034bf0ce7a39e4563b974350a5d498 100644 (file)
@@ -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;
 
@@ -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;
@@ -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;
        }
@@ -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;
                }
 
@@ -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;
                }