Fix handling of "%z" in format strings for MinGW in all cases
MinGW only supports "%z" directly when using ANSI stdio, but this is not always the case (even if it often is, as just including any standard C++ header enables ANSI stdio as a side effect). Translate "%z" to "%I" for it as well as for MSVC to ensure that it always works. Closes #17492.
This commit is contained in:
@@ -198,16 +198,22 @@ public:
|
|||||||
|
|
||||||
switch ( *format )
|
switch ( *format )
|
||||||
{
|
{
|
||||||
#ifdef __VISUALC__
|
// MSVC doesn't support C99 'z' size modifier, but it uses
|
||||||
|
// 'I' with exactly the same meaning.
|
||||||
|
//
|
||||||
|
// MinGW does support 'z' but only in ANSI stdio mode, and
|
||||||
|
// we can't be sure that this is what is actually going to
|
||||||
|
// be used, application code could explicitly define
|
||||||
|
// __USE_MINGW_ANSI_STDIO=0 (e.g. because it needs legacy
|
||||||
|
// behaviour for its own printf() calls), so we map it to
|
||||||
|
// 'I' for it too.
|
||||||
|
#if defined(__VISUALC__) || defined(__MINGW32__)
|
||||||
case 'z':
|
case 'z':
|
||||||
// Used for size_t printing (e.g. %zu) and is in C99,
|
|
||||||
// but is not portable, MSVC uses 'I' with the same
|
|
||||||
// meaning.
|
|
||||||
ChangeFmtChar('I');
|
ChangeFmtChar('I');
|
||||||
format++;
|
format++;
|
||||||
size = Size_Default;
|
size = Size_Default;
|
||||||
break;
|
break;
|
||||||
#endif // __VISUALC__
|
#endif // __VISUALC__ || __MINGW32__
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
size = Size_Short;
|
size = Size_Short;
|
||||||
|
Reference in New Issue
Block a user