According to standard C99, the swprintf and vswprintf functions return a negative value if the buffer is insufficient (contrary to snprintf). As far as I can read the standard, the contents of the buffer in this case is unspecified, but this patch makes it match MSVC, which does null terminate it.
Signed-off-by: Martin Storsjö <mar...@martin.st> --- mingw-w64-headers/crt/stdio.h | 3 ++- mingw-w64-headers/crt/wchar.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h index b48241831..9b0ec6250 100644 --- a/mingw-w64-headers/crt/stdio.h +++ b/mingw-w64-headers/crt/stdio.h @@ -1306,7 +1306,8 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, __builti __mingw_ovr int __cdecl vsnwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, va_list arg) { - return __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE | UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, s, n, format, NULL, arg); + int ret = __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE, s, n, format, NULL, arg); + return ret < 0 ? -1 : ret; } #endif diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h index 3fde2a6fb..f4e10e2f4 100644 --- a/mingw-w64-headers/crt/wchar.h +++ b/mingw-w64-headers/crt/wchar.h @@ -824,7 +824,8 @@ int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, __builti __mingw_ovr int __cdecl vsnwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, va_list arg) { - return __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE | UCRTBASE_PRINTF_STANDARD_SNPRINTF_BEHAVIOUR, s, n, format, NULL, arg); + int ret = __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE, s, n, format, NULL, arg); + return ret < 0 ? -1 : ret; } #endif -- 2.17.1 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public