crt: Fix i386 _beginthreadex to accept NULL thrdaddr Function _beginthreadex in msvcr70+ use dummy stack value for thrdaddr pointer argument if caller specify NULL. This seems to be for compatibility with older Windows versions where CreateThread crashes if NULL thrdaddr pointer is supplied. Pass pointer to dummy stack value in mingw-w64 i386 _beginthreadex wrapper if the supplied pointer is NULL. This allows allows applications to call _beginthreadex with NULL thrdaddr argument for CRT any build without crashing on older systems. Signed-off-by: LIU Hao <lh_mouse@126.com>
diff --git a/mingw-w64-crt/misc/i386__beginthreadex.c b/mingw-w64-crt/misc/i386__beginthreadex.c index b23f654..de5a07c 100644 --- a/mingw-w64-crt/misc/i386__beginthreadex.c +++ b/mingw-w64-crt/misc/i386__beginthreadex.c
@@ -45,7 +45,8 @@ } thread_args[0] = (void *)start_address; thread_args[1] = arglist; - ret = __msvcrt_beginthreadex(security, stack_size, thread_func, thread_args, initflag, thrdaddr); + /* pre-msvcr70 versions of _beginthreadex do not change NULL thrdaddr to dummy stack value */ + ret = __msvcrt_beginthreadex(security, stack_size, thread_func, thread_args, initflag, thrdaddr ?: &(unsigned){0}); if (!ret) free(thread_args); return ret;