Hi On MSVCRT, wprintf expects that %s is wide char string, but for not MSVCRT, this is not true. When using -D__USE_MINGW_ANSI_STDIO=1 on MINGW, mingw doesn't use MSVCRT. Therefore, compiling on mingw with -D__USE_MINGW_ANSI_STDIO=1 and redirecting stderr to a file, the printing result is corrupt. We should use fputws simply. A patch is attached. -------------- next part -------------- A non-text attachment was scrubbed... Name: 0001-win_utf8_io.c-Use-fputws-instead-of-fwprintf.patch Type: application/octet-stream Size: 823 bytes Desc: not available Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20140913/f1410d7a/attachment.obj
NAKAI Yuta <nak5124 at live.jp> ?????(?) ? ????? ?????? Fri, 12 Sep 2014 19:28:32 +0400:> When using -D__USE_MINGW_ANSI_STDIO=1 on MINGW, mingw doesn't use MSVCRT.Interesting. Currently FLAC has flac_snprintf() function in src/share/grabbag/snprintf.c (and its exact copy local_snprintf() in src/libFLAC/metadata_iterators.c): /* * The _MSC_VER code below attempts to modify the return code for snprintf_s * to something that is more compatible with the behaviour of the ISO C version. */ int flac_snprintf(char *str, size_t size, const char *fmt, ...) { va_list va; int rc ; va_start (va, fmt); #ifdef _MSC_VER rc = vsnprintf_s (str, size, _TRUNCATE, fmt, va); rc = (rc > 0) ? rc : (size == 0 ? 1024 : size * 2); #else rc = vsnprintf (str, size, fmt, va); #endif va_end (va); return rc; } The code implies that non-MSVC vsnprintf always has standart behavior. But it looks like MinGW has 2 versions of vsnprintf: its own standard-conforming and non-conforming from msvcrt.dll. So flac_snprintf() can return unexpected value when compiled with MinGW.
Erik de Castro Lopo
2014-Sep-20 22:46 UTC
[flac-dev] win_utf8_io.c: Use fputws instead of fwprintf
NAKAI Yuta wrote:> Hi > On MSVCRT, wprintf expects that %s is wide char string, but for not MSVCRT, > this is not true. > When using -D__USE_MINGW_ANSI_STDIO=1 on MINGW, mingw doesn't use MSVCRT. > > Therefore, compiling on mingw with -D__USE_MINGW_ANSI_STDIO=1 and redirecting > stderr to a file, the printing result is corrupt. > We should use fputws simply. > A patch is attached.Patch applied. Thanks. Cheers, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/