Skip to content

eBPF-based security platform

treewide: spell the printf format attribute __printf()

Daniel Borkmann76b3fc938792
diff --git a/include/shirudo/compiler.h b/include/shirudo/compiler.h
new file mode 100644
index 00000000..278d4fcc
--- /dev/null
+++ b/include/shirudo/compiler.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * Function attributes spelled the kernel's way.
+ */
+
+#ifndef SHIRUDO_COMPILER_H
+#define SHIRUDO_COMPILER_H
+
+#define __printf(a, b) __attribute__((format(printf, a, b)))
+
+#endif /* SHIRUDO_COMPILER_H */
diff --git a/include/shirudo/misc.h b/include/shirudo/misc.h
index fca5fbf9..2891df34 100644
--- a/include/shirudo/misc.h
+++ b/include/shirudo/misc.h
@@ -12,6 +12,8 @@
#include <stdint.h>
#include <stdlib.h>
+#include <shirudo/compiler.h>
+
/*
* Defined as asm-generic/int-ll64.h defines them on x86-64, arm64 and
* riscv64, so a file that also includes <linux/types.h> sees the same
diff --git a/include/shirudo/string.h b/include/shirudo/string.h
index ff4ab37b..21ccb038 100644
--- a/include/shirudo/string.h
+++ b/include/shirudo/string.h
@@ -46,9 +46,9 @@ ssize_t strscpy(char *dst, const char *src, size_t size);
* the arguments as a va_list.
*/
int strsprintf(char *buf, size_t size, const char *fmt, ...)
- __attribute__((format(printf, 3, 4), warn_unused_result));
+ __printf(3, 4) __attribute__((warn_unused_result));
int vstrsprintf(char *buf, size_t size, const char *fmt, va_list ap)
- __attribute__((format(printf, 3, 0), warn_unused_result));
+ __printf(3, 0) __attribute__((warn_unused_result));
/*
* What the functions above replace, refused once the headers included
diff --git a/testing/unit/unit.h b/testing/unit/unit.h
index 08517bb4..05126a5d 100644
--- a/testing/unit/unit.h
+++ b/testing/unit/unit.h
@@ -34,7 +34,7 @@ struct unit_suite {
extern const struct unit_suite unit_suite;
void unit_fail(const char *file, int line, const char *fmt, ...)
- __attribute__((format(printf, 3, 4)));
+ __printf(3, 4);
__attribute__((noreturn)) void unit_abort(void);
__attribute__((noreturn)) void unit_skip(const char *reason);
void unit_fail_mem(const char *file, int line, const char *what,
diff --git a/util/attest.c b/util/attest.c
index 679db349..145c1199 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -625,7 +625,7 @@ struct reporter {
};
static void say(struct reporter *r, bool ok, const char *fmt, ...)
- __attribute__((format(printf, 3, 4)));
+ __printf(3, 4);
static void say(struct reporter *r, bool ok, const char *fmt, ...)
{
@@ -651,7 +651,7 @@ static void say(struct reporter *r, bool ok, const char *fmt, ...)
}
static void note(struct reporter *r, const char *fmt, ...)
- __attribute__((format(printf, 2, 3)));
+ __printf(2, 3);
static void note(struct reporter *r, const char *fmt, ...)
{
diff --git a/util/log.h b/util/log.h
index 9b7b8cca..8824a449 100644
--- a/util/log.h
+++ b/util/log.h
@@ -10,15 +10,17 @@
#include <stdarg.h>
+#include <shirudo/compiler.h>
+
void log_init(void);
void pr_err(const char *fmt, ...)
- __attribute__((format(printf, 1, 2)));
+ __printf(1, 2);
void pr_warn(const char *fmt, ...)
- __attribute__((format(printf, 1, 2)));
+ __printf(1, 2);
void pr_info(const char *fmt, ...)
- __attribute__((format(printf, 1, 2)));
+ __printf(1, 2);
void pr_audit(const char *fmt, ...)
- __attribute__((format(printf, 1, 2)));
+ __printf(1, 2);
#endif /* SHIRUDO_LOG_H */
diff --git a/util/malloc.h b/util/malloc.h
index f8122e0f..924dbd83 100644
--- a/util/malloc.h
+++ b/util/malloc.h
@@ -13,6 +13,8 @@
#include <stdlib.h>
#include <string.h>
+#include <shirudo/compiler.h>
+
/*
* NULL on failure, never die(): a one-shot CLI reports -ENOMEM up its
* normal path. A zero size still returns a freeable pointer, so NULL
@@ -40,7 +42,7 @@ char *xstrdup(const char *s);
char *xstrndup(const char *s, size_t n);
/* A formatted string, freed with xstrfree(); NULL if formatting fails. */
-char *xasprintf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+char *xasprintf(const char *fmt, ...) __printf(1, 2);
/*
* Scrubs, so key material, signatures and TPM auth do not linger in
diff --git a/util/preflight.c b/util/preflight.c
index bbc4256f..869df66e 100644
--- a/util/preflight.c
+++ b/util/preflight.c
@@ -58,7 +58,7 @@ static void pass(struct shirudo_preflight_check *c)
c->ok = true;
}
-__attribute__((format(printf, 3, 4)))
+__printf(3, 4)
static void fail(struct shirudo_preflight_result *r,
struct shirudo_preflight_check *c, const char *fmt, ...)
{