From 98260c586216909934abfe63beeebff3171f4479 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Tue, 6 Jul 2021 06:29:49 +0200 Subject: [PATCH] LibC+Utilities: Add `gnu::format` attributes Without these attributes present on these custom formatting functions, Clang would warn use about nonliteral format strings. As an added bonus, we now get type checking on these. --- Userland/Libraries/LibC/getopt.cpp | 2 +- Userland/Utilities/test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibC/getopt.cpp b/Userland/Libraries/LibC/getopt.cpp index 1fd5203351..e3d4f6f56d 100644 --- a/Userland/Libraries/LibC/getopt.cpp +++ b/Userland/Libraries/LibC/getopt.cpp @@ -22,7 +22,7 @@ char* optarg = nullptr; // processed". Well, this is how we do it. static size_t s_index_into_multioption_argument = 0; -static inline void report_error(const char* format, ...) +[[gnu::format(printf, 1, 2)]] static inline void report_error(const char* format, ...) { if (!opterr) return; diff --git a/Userland/Utilities/test.cpp b/Userland/Utilities/test.cpp index a868348411..f662c8d259 100644 --- a/Userland/Utilities/test.cpp +++ b/Userland/Utilities/test.cpp @@ -16,7 +16,7 @@ bool g_there_was_an_error = false; -[[noreturn]] static void fatal_error(const char* format, ...) +[[noreturn, gnu::format(printf, 1, 2)]] static void fatal_error(const char* format, ...) { fputs("\033[31m", stderr);