curl_threads: fix MSVC compiler warning#1717
Conversation
|
Coverage increased (+0.09%) to 75.355% when pulling 06a57ae42b71eee298c66e301b7b228161de3ae8 on MarcelRaad:msvc11_c4306 into 53d137d on curl:master. |
Use LongToHandle to convert from long to HANDLE in the Win32 implementation. This should fix the following warning when compiling with MSVC 11 (2012) in 64-bit mode: lib\curl_threads.c(113): warning C4306: 'type cast' : conversion from 'long' to 'HANDLE' of greater size Closes curl#1717
06a57ae to
12b4fb7
Compare
|
I can't reproduce this warning in VS 2010 in a test project at W4 or 2015 in curl project at W4. original mingw only defines LongToHandle if win64 so that will need to be addressed. from what i understand beginthreadex can return 0 or -1 uintptr_t on error (0 but it contradicts because -1 in some versions if startaddress is null). CreateThread can return 0 HANDLE on error. do you get a warning if you drop the L for example if((t == 0) || (t == (curl_thread_t)(uintptr_t)-1)) { |
|
I tried in VS2010 curl project at W4 and I can reproduce it there, this fixes it: diff --git a/lib/curl_threads.c b/lib/curl_threads.c
index 1989710..53fed9c 100644
--- a/lib/curl_threads.c
+++ b/lib/curl_threads.c
@@ -110,7 +110,7 @@ curl_thread_t Curl_thread_create(unsigned int (CURL_STDCALL *func) (void *),
#else
t = (curl_thread_t)_beginthreadex(NULL, 0, func, arg, 0, NULL);
#endif
- if((t == 0) || (t == (curl_thread_t)-1L)) {
+ if((t == 0) || (t == (curl_thread_t)(uintptr_t)-1)) {
#ifdef _WIN32_WCE
DWORD gle = GetLastError();
errno = ((gle == ERROR_ACCESS_DENIED || |
|
Thanks @jay! That's strange as original MinGW cannot even compile for Win64. |
|
@jay I can compile successfully with MinGW and |
You're right, I had misinterpreted that, thanks for following up. |
Use
LongToHandleto convert fromlongtoHANDLEin the Win32implementation.
This should fix the following warning when compiling with
MSVC 11 (2012) in 64-bit mode visible in #1711:
LongToHandleis available in the February 2003 Platform SDK, so I think we should be safe. Alternatively,INVALID_HANDLE_VALUEcould be used (the documented value in the_beginthreadexdocumentation is-1L, though).