From 06458cb89fb8449f377b0b782404b9a9cbe3ae2d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 10 Feb 2016 15:22:51 +0100 Subject: [PATCH] Fix handling of strings in wxPrintf() when using recent MinGW MinGW-w64 (and apparently TDM too) defaults to using ANSI stdio functions nowadays, which interpret format specifiers such as "%s" and "%c" in wide string functions in the standard-conforming way, i.e. still expecting the arguments of "char*" type, and not "wchar_t*" as MSVC and older MinGW did. --- docs/changes.txt | 1 + src/common/strvararg.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7fd8d7de54..e6b20ccd1c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -207,6 +207,7 @@ wxMSW: - Return correct OS version under Windows 8.1 and later. - Fix crash in wxD2DContext when using non-MSVC compiler (iwbnwif). - Notify shell about the changes done by wxMimeTypesManager (Maarten Bent). +- Fix wxPrintf() and friends when using MinGW with ANSI stdio option. wxOSX/Cocoa: diff --git a/src/common/strvararg.cpp b/src/common/strvararg.cpp index 0196e06ee9..d4550dbfd1 100644 --- a/src/common/strvararg.cpp +++ b/src/common/strvararg.cpp @@ -410,7 +410,13 @@ private: size_t m_nCopied; }; -#if defined(__WINDOWS__) && !defined(__CYGWIN__) +// Distinguish between the traditional Windows (and MSVC) behaviour and Cygwin +// (which is always Unix-like) and MinGW which can use either depending on the +// "ANSI stdio" option value (which is normally set to either 0 or 1, but test +// for it in a way which works even if it's not defined at all, just in case). +#if defined(__WINDOWS__) && \ + !defined(__CYGWIN__) && \ + (!defined(__MINGW32__) || (__USE_MINGW_ANSI_STDIO +0 == 0)) // on Windows, we should use %s and %c regardless of the build: class wxPrintfFormatConverterWchar : public wxFormatConverterBase