Enable format warnings under MinGW

This commit is contained in:
Tim Angus 2025-09-07 15:45:57 +01:00
parent 07b9c1bd83
commit 65a1da4a01
3 changed files with 12 additions and 3 deletions

View File

@ -30,7 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
static HINTERNET hInternet = NULL;
static HINTERNET hUrl = NULL;
static void DropIf(qboolean condition, const char *fmt, ...)
static Q_PRINTF_FUNC(2, 3) void DropIf(qboolean condition, const char *fmt, ...)
{
char buffer[1024];

View File

@ -94,7 +94,7 @@ int atoi( const char *string );
int _atoi( const char **stringPtr );
long strtol( const char *nptr, char **endptr, int base );
int Q_vsnprintf( char *buffer, size_t length, const char *fmt, va_list argptr );
int Q_vsnprintf( char *buffer, size_t length, const char *fmt, va_list argptr ) Q_PRINTF_FUNC(3, 0);
int sscanf( const char *buffer, const char *fmt, ... ) Q_SCANF_FUNC(2, 3);

View File

@ -108,7 +108,16 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef __GNUC__
#define Q_UNUSED_VAR __attribute__((unused))
#define Q_NO_RETURN __attribute__((noreturn))
#ifdef __MINGW32__
// For some reason MinGW wants both gnu_printf and ms_printf
#define Q_PRINTF_FUNC(fmt, va) \
__attribute__((format(gnu_printf, fmt, va))) \
__attribute__((format(ms_printf, fmt, va)))
#else
#define Q_PRINTF_FUNC(fmt, va) __attribute__((format(printf, fmt, va)))
#endif
#define Q_SCANF_FUNC(fmt, va) __attribute__((format(scanf, fmt, va)))
#define Q_ALIGN(x) __attribute__((aligned(x)))
#else
@ -168,7 +177,7 @@ typedef int intptr_t;
#ifdef _WIN32
// vsnprintf is ISO/IEC 9899:1999
// abstracting this to make it portable
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap);
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap) Q_PRINTF_FUNC(3, 0);
#else
#define Q_vsnprintf vsnprintf
#endif