telnet.c warning #2696

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

Comments

Projects
None yet
2 participants
@gvanem
Member

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

This comment has been minimized.

Show comment
Hide comment
@gvanem

gvanem Jun 29, 2018

Member

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);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Member

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

This comment has been minimized.

Show comment
Hide comment
@bagder

bagder Jun 29, 2018

Member

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

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... ?

@gvanem

This comment has been minimized.

Show comment
Hide comment
@gvanem

gvanem Jun 29, 2018

Member

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);
Member

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 added a commit that referenced this issue Jun 29, 2018

telnet: fix clang warnings
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 in ab4cf99 Jul 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment