windows: uv_fs_readdir
segfaults on mingw #990
Description
Test code is here.
uv_fs_readdir
uses swprintf
, but there exist two different swprintf due to legacy issues: one with count
argument (iso-conforming) and without count
(non-conforming). msvc and mingw-w64 (!= mingw) provide iso-conforming functions as default.
libuv uses iso-conforming one as default, and uses non-conforming one if _CRT_NON_CONFORMING_SWPRINTFS
is defined. (src/win/fs.c)
However, mingw only provides non-conforming one regardless of the macro. So libuv calls swprintf(path2, len + 3, fmt, pathw);
but mingw only knows 3-arg function. This causes warning on build time...
src/win/fs.c:744:3: warning: passing argument 2 of 'swprintf' makes pointer from integer without a cast
...and it segfaults on runtime.
This only occurs on mingw, not mingw-w64 nor msvc.
Easy workaround is to build libuv with make CFLAGS="-D_CRT_NON_CONFORMING_SWPRINTFS"
. This will also work for mingw-w64 and msvc.