From 83119a990a160e9c1e19dc06e04ae8f947a57904 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 4 Feb 2018 08:03:51 -0600 Subject: [PATCH] Fix Q_vsnprintf for mingw-w64 By default mingw-w64 uses Microsoft's broken _vsnprintf() in msvcrt.dll. It can be overriden by defining __USE_MINGW_ANSI_STDIO but let's just use the same behavior for both MSVC and mingw-w64. Reported by @birdstakes. --- code/qcommon/q_shared.c | 7 ++++--- code/qcommon/q_shared.h | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/code/qcommon/q_shared.c b/code/qcommon/q_shared.c index 820c862c..aa17f1c1 100644 --- a/code/qcommon/q_shared.c +++ b/code/qcommon/q_shared.c @@ -746,13 +746,14 @@ qboolean Q_isintegral( float f ) return (int)f == f; } -#ifdef _MSC_VER +#ifdef _WIN32 /* ============= Q_vsnprintf - + Special wrapper function for Microsoft's broken _vsnprintf() function. -MinGW comes with its own snprintf() which is not broken. +MinGW comes with its own vsnprintf() which is not broken. mingw-w64 +however, uses Microsoft's broken _vsnprintf() function. ============= */ diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h index 4c1b821a..629334af 100644 --- a/code/qcommon/q_shared.h +++ b/code/qcommon/q_shared.h @@ -177,13 +177,15 @@ typedef int intptr_t; typedef unsigned __int32 uint32_t; typedef unsigned __int16 uint16_t; typedef unsigned __int8 uint8_t; +#else + #include +#endif +#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); #else - #include - #define Q_vsnprintf vsnprintf #endif