Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

windows: uv_fs_readdir segfaults on mingw #990

Closed
klutzy opened this issue Nov 9, 2013 · 1 comment
Closed

windows: uv_fs_readdir segfaults on mingw #990

klutzy opened this issue Nov 9, 2013 · 1 comment

Comments

@klutzy
Copy link

klutzy commented Nov 9, 2013

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.

@klutzy
Copy link
Author

klutzy commented Nov 9, 2013

mingw 4.1 will provide iso-conforming swprintf: http://sourceforge.net/p/mingw/bugs/2018/
However 4.1 doesn't provide non-conforming version, so CFLAGS="-D_CRT_NON_CONFORMING_SWPRINTFS" trick will make broken libuv on mingw 4.1.
I think we should check mingw version instead of _CRT_NON_CONFORMING_SWPRINTFS, since the awkward thing occurs only on mingw < 4.1, not on msvc/mingw-w64.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant