Skip to content

telnet.c warning #2696

Closed
Closed

Description

@gvanem

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

Activity

  1. gvanem commented on Jun 29, 2018

    @gvanem
    ContributorAuthor

    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);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. bagder commented on Jun 29, 2018

    @bagder
    Member

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

  3. gvanem commented on Jun 29, 2018

    @gvanem
    ContributorAuthor

    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);
  4. added a commit that references this issue on Jun 29, 2018
    ea421ae
  5. locked as resolved and limited conversation to collaborators on Sep 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions