Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telnet.c warning #2696

Closed
gvanem opened this issue Jun 29, 2018 · 3 comments
Closed

telnet.c warning #2696

gvanem opened this issue Jun 29, 2018 · 3 comments
Labels
build Windows Windows-specific

Comments

@gvanem
Copy link
Contributor

gvanem commented Jun 29, 2018

At line 1401 in lib/telnet.c:

  event_handle = (WSAEVENT)create_event_func();

I get this warning when compiling with clang-cl ver 6:

telnet.c(1401,28):  warning: cast from function call of type 'int' to non-matching 
type 'HANDLE' (aka 'void *') [-Wbad-function-cast]
  event_handle = (WSAEVENT)create_event_func();
                           ^~~~~~~~~~~~~~~~~~~

clang-cl is quite correct; a WSAEVENT is always 32-bit and HANDLE is a void* which could be 64-bit wide.

A fix is maybe to use another typedef for the WSACreateEvent() function. Like:

  typedef WSAEVENT (WINAPI *WSOCK2_EVENT)(void);
  ...
  WSOCK2_EVENT create_event_func;
  ...
  create_event_func = (WSOCK2_EVENT) GetProcAddress(wsock2, "WSACreateEvent");
@gvanem
Copy link
Contributor Author

gvanem commented Jun 29, 2018

FYI, there is also this similar warning:

curl_threads.c(111,22):  warning: cast from function call of type 
'uintptr_t' (aka 'unsigned int') to non-matching type 'HANDLE' (aka 'void *') [-Wbad-function-cast]
  t = (curl_thread_t)_beginthreadex(NULL, 0, func, arg, 0, NULL);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@bagder
Copy link
Member

bagder commented Jun 29, 2018

Can you suggest full patches too, since you have the compiler there to verify that the warnings actually go away... ?

@bagder bagder added build Windows Windows-specific labels Jun 29, 2018
@gvanem
Copy link
Contributor Author

gvanem commented Jun 29, 2018

Here is my suggestion:

--- a/telnet.c 2018-06-14 09:28:16
+++ b/telnet.c 2018-06-29 15:04:08
@@ -92,6 +92,7 @@
 #endif

 #ifdef USE_WINSOCK
+typedef WSAEVENT (WINAPI *WSOCK2_EVENT)(void);
 typedef FARPROC WSOCK2_FUNC;
 static CURLcode check_wsock2(struct Curl_easy *data);
 #endif
@@ -1306,7 +1307,7 @@
 #ifdef USE_WINSOCK
   HMODULE wsock2;
   WSOCK2_FUNC close_event_func;
-  WSOCK2_FUNC create_event_func;
+  WSOCK2_EVENT create_event_func;
   WSOCK2_FUNC event_select_func;
   WSOCK2_FUNC enum_netevents_func;
   WSAEVENT event_handle;
@@ -1360,7 +1361,7 @@
   }

   /* Grab a pointer to WSACreateEvent */
-  create_event_func = GetProcAddress(wsock2, "WSACreateEvent");
+  create_event_func = (WSOCK2_EVENT) GetProcAddress(wsock2, "WSACreateEvent");
   if(create_event_func == NULL) {
     failf(data, "failed to find WSACreateEvent function (%u)", GetLastError());
     FreeLibrary(wsock2);

bagder pushed a commit that referenced this issue Jun 29, 2018
telnet.c(1401,28): warning: cast from function call of type 'int' to
non-matching type 'HANDLE' (aka 'void *') [-Wbad-function-cast]

Fixes #2696
@bagder bagder closed this as completed in ab4cf99 Jul 1, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
build Windows Windows-specific
Development

No branches or pull requests

2 participants