crtdll.dll runtime does not suppport 64-bit printf/scanf modifiers. So when targeting crtdll.dll runtime and not using MinGW-w64 stdio functions then do not define any 64-bit modifier in inttypes.h header file.
crtdll.dll does not interpret %I64d modifier and does not read next argument from variadic function call. So usage of this modifier cause shifting of all variadic arguments. This change will cause compile errors for crtdll.dll application which are going to use PRId64 without __USE_MINGW_ANSI_STDIO. Compile error is better than random runtime crashes or wrong behavior by corruption of printf/scanf stack. gcc automatically predefines macro __CRTDLL__ when compiling for crtdll.dll runtime, so use it in inttypes.h checks. crtdll.dll based applications which use 64-bit int stdio support had to use -D__USE_MINGW_ANSI_STDIO=1 compile flag even prior this change. Non-crtdll.dll based applications (msvcrt.dll or ucrt; which is the majority) are not affected by this change. So there there should not be any issue with this change and it should help to prevent stdio function overflows for crtdll.dll applications. --- mingw-w64-headers/crt/inttypes.h | 48 +++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/mingw-w64-headers/crt/inttypes.h b/mingw-w64-headers/crt/inttypes.h index 881025c0d0b9..2fe9b3ca25ef 100644 --- a/mingw-w64-headers/crt/inttypes.h +++ b/mingw-w64-headers/crt/inttypes.h @@ -28,6 +28,7 @@ typedef struct { * length specifier. It appears to treat "ll" as "l". * The non-standard I64 length specifier causes warning in GCC, * but understood by MS runtime functions. + * crtdll.dll runtime does not support any 64-bit modifier. */ #if defined(_UCRT) || __USE_MINGW_ANSI_STDIO #define PRId64 "lld" @@ -36,7 +37,7 @@ typedef struct { #define PRIu64 "llu" #define PRIx64 "llx" #define PRIX64 "llX" -#else +#elif !defined(__CRTDLL__) #define PRId64 "I64d" #define PRIi64 "I64i" #define PRIo64 "I64o" @@ -278,6 +279,51 @@ typedef struct { #define SCNuFAST8 "hhu" #endif /* __STDC_VERSION__ >= 199901 */ +#if defined(__CRTDLL__) && !defined(__USE_MINGW_ANSI_STDIO) +/* + * crtdll.dll runtime does not support any 64-bit modifier. + * Undef all previously defined 64-bit modifiers. + */ +#undef PRIdLEAST64 +#undef PRIdFAST64 +#undef PRIdMAX +#undef PRIiLEAST64 +#undef PRIiFAST64 +#undef PRIiMAX +#undef PRIoLEAST64 +#undef PRIoFAST64 +#undef PRIoMAX +#undef PRIuLEAST64 +#undef PRIuFAST64 +#undef PRIuMAX +#undef PRIxLEAST64 +#undef PRIxFAST64 +#undef PRIxMAX +#undef PRIXLEAST64 +#undef PRIXFAST64 +#undef PRIXMAX +#undef SCNd64 +#undef SCNdLEAST64 +#undef SCNdFAST64 +#undef SCNdMAX +#undef SCNi64 +#undef SCNiLEAST64 +#undef SCNiFAST64 +#undef SCNiMAX +#undef SCNo64 +#undef SCNoLEAST64 +#undef SCNoFAST64 +#undef SCNoMAX +#undef SCNx64 +#undef SCNxLEAST64 +#undef SCNxFAST64 +#undef SCNxMAX +#undef SCNu64 +#undef SCNuLEAST64 +#undef SCNuFAST64 +#undef SCNuMAX +#endif + intmax_t __cdecl imaxabs (intmax_t j); #ifndef __CRT__NO_INLINE __CRT_INLINE intmax_t __cdecl imaxabs (intmax_t j) -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public