From c9e13f012853145d72567cfc6284e63a1d17e55d Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 6 Sep 2022 18:25:38 +0200 Subject: [PATCH] Add attribute(format) to *printf to detect ill-formed calls to those functions --- kernel/include/std/stdio.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/include/std/stdio.h b/kernel/include/std/stdio.h index 6563ab59..21c6cd64 100644 --- a/kernel/include/std/stdio.h +++ b/kernel/include/std/stdio.h @@ -2,9 +2,11 @@ #include #include -int printf(const char* fmt, ...); -int sprintf(char* __s, const char* fmt, ...); -int snprintf(char* __s, size_t max, const char* fmt, ...); +#define PRINTF_LIKE(n, m) __attribute__((format(printf, n, m))) + +int printf(const char* fmt, ...) PRINTF_LIKE(1, 2); +int sprintf(char* __s, const char* fmt, ...) PRINTF_LIKE(2, 3); +int snprintf(char* __s, size_t max, const char* fmt, ...) PRINTF_LIKE(3, 4); int vprintf(const char* fmt, va_list ap); int vsprintf(char* __s, const char* fmt, va_list ap); int vsnprintf(char* __s, size_t max, const char* fmt, va_list ap); \ No newline at end of file