From 01b3b5066d146c228bb1c6656a61d826de67b549 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Thu, 4 Feb 2021 17:15:28 -0700 Subject: [PATCH] Add printf-like macro. This should help catch some formatting bugs. --- src/common/log.h | 2 +- src/common/types.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/log.h b/src/common/log.h index 1223ce037..132b65d36 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -46,7 +46,7 @@ void SetFilterLevel(LOGLEVEL level); // writes a message to the log void Write(const char* channelName, const char* functionName, LOGLEVEL level, const char* message); -void Writef(const char* channelName, const char* functionName, LOGLEVEL level, const char* format, ...); +void Writef(const char* channelName, const char* functionName, LOGLEVEL level, const char* format, ...) printflike(4, 5); void Writev(const char* channelName, const char* functionName, LOGLEVEL level, const char* format, va_list ap); } // namespace Log diff --git a/src/common/types.h b/src/common/types.h index 839b585e7..9a7645c93 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -49,6 +49,12 @@ char (&__countof_ArraySizeHelper(T (&array)[N]))[N]; #define offsetof(st, m) ((size_t)((char*)&((st*)(0))->m - (char*)0)) #endif +#ifdef __GNUC__ +#define printflike(n,m) __attribute__((format(printf,n,m))) +#else +#define printflike(n,m) +#endif + // disable warnings that show up at warning level 4 // TODO: Move to build system instead #ifdef _MSC_VER