diff --git a/Source/appfat.h b/Source/appfat.h index 9db346ede..72a721f9f 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -7,10 +7,12 @@ #include +#include "../defs.h" + namespace devilution { -[[noreturn]] void app_fatal(const char *pszFmt, ...); -void DrawDlg(const char *pszFmt, ...); +[[noreturn]] void app_fatal(const char *pszFmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2); +void DrawDlg(const char *pszFmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2); #ifdef _DEBUG [[noreturn]] void assert_fail(int nLineNo, const char *pszFile, const char *pszFail); #endif diff --git a/SourceS/console.h b/SourceS/console.h index ec0ce2bb3..31583ad19 100644 --- a/SourceS/console.h +++ b/SourceS/console.h @@ -1,6 +1,8 @@ #pragma once #if defined(_WIN64) || defined(_WIN32) +#include "../defs.h" + // Suppress definitions of `min` and `max` macros by : #define NOMINMAX 1 #define WIN32_LEAN_AND_MEAN @@ -8,7 +10,9 @@ namespace devilution { -void printInConsole(const char *fmt, ...) +void printInConsole(const char *fmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2); + +inline void printInConsole(const char *fmt, ...) { static HANDLE stderrHandle = NULL; if (stderrHandle == NULL) { diff --git a/SourceS/sdl2_to_1_2_backports.h b/SourceS/sdl2_to_1_2_backports.h index 564daa319..225deb220 100644 --- a/SourceS/sdl2_to_1_2_backports.h +++ b/SourceS/sdl2_to_1_2_backports.h @@ -10,6 +10,7 @@ #include #include "console.h" +#include "../defs.h" #include "../SourceX/stubs.h" #define WINDOW_ICON_NAME 0 @@ -54,6 +55,8 @@ #define SDL_JoystickID Sint32 #define SDL_JoystickNameForIndex SDL_JoystickName +void SDL_Log(const char *fmt, ...) DVL_PRINTF_ATTRIBUTE(1, 2); + inline void SDL_Log(const char *fmt, ...) { char message[256]; diff --git a/defs.h b/defs.h index a817f9948..1223e46d8 100644 --- a/defs.h +++ b/defs.h @@ -203,3 +203,10 @@ #else #define DVL_ATTRIBUTE_ALWAYS_INLINE #endif + +#if DVL_HAVE_ATTRIBUTE(format) || (defined(__GNUC__) && !defined(__clang__)) +#define DVL_PRINTF_ATTRIBUTE(fmtargnum, firstarg) \ + __attribute__((__format__(__printf__, fmtargnum, firstarg))) +#else +#define DVL_PRINTF_ATTRIBUTE(fmtargnum) +#endif