crt/mingw_pformat: Initialize `mbstate_t` structure properly When `wcrtomb()` is called with a null wide character (second argument) it is required to output a sequence of bytes to 'restore the initial shift state'. For this function, the `mbstate_t` structure shall be initialized before the call. Previous code passed an uninitialized structure and expected `wcrtomb(buf, L'\0', &state)` to initialize `state` to the initial shift state, which was incorrect. Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/stdio/mingw_pformat.c b/mingw-w64-crt/stdio/mingw_pformat.c index d094e7a..4e41b4d 100644 --- a/mingw-w64-crt/stdio/mingw_pformat.c +++ b/mingw-w64-crt/stdio/mingw_pformat.c
@@ -569,8 +569,8 @@ * output quota is honoured. */ char buf[16]; - mbstate_t state; - int len = wcrtomb(buf, L'\0', &state); + mbstate_t state = {0}; + int len; if( (stream->precision >= 0) && (count > stream->precision) ) /*