bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Missing type cast in select.c


From: Eli Zaretskii
Subject: Missing type cast in select.c
Date: Thu, 08 Jul 2021 17:17:55 +0300

Compiling Gnulib's select.c with mingw.org's MinGW produces the
following warnings:

     In file included from select.c:24:
     select.c: In function 'rpl_select':
     select.c:534:25: warning: passing argument 1 of 'rpl_fd_isset' makes 
integer from pointer without a cast [-Wint-conversion]
       534 |           if (FD_ISSET (h, &handle_rfds))
           |                         ^
           |                         |
           |                         HANDLE {aka void *}
     ./sys/select.h:640:22: note: expected 'SOCKET' {aka 'unsigned int'} but 
argument is of type 'HANDLE' {aka 'void *'}
       640 | rpl_fd_isset (SOCKET fd, fd_set * set)
           |               ~~~~~~~^~
     select.c:536:25: warning: passing argument 1 of 'rpl_fd_isset' makes 
integer from pointer without a cast [-Wint-conversion]
       536 |           if (FD_ISSET (h, &handle_wfds))
           |                         ^
           |                         |
           |                         HANDLE {aka void *}
     ./sys/select.h:640:22: note: expected 'SOCKET' {aka 'unsigned int'} but 
argument is of type 'HANDLE' {aka 'void *'}
       640 | rpl_fd_isset (SOCKET fd, fd_set * set)
           |               ~~~~~~~^~
     select.c:538:25: warning: passing argument 1 of 'rpl_fd_isset' makes 
integer from pointer without a cast [-Wint-conversion]
       538 |           if (FD_ISSET (h, &handle_xfds))
           |                         ^
           |                         |
           |                         HANDLE {aka void *}
     ./sys/select.h:640:22: note: expected 'SOCKET' {aka 'unsigned int'} but 
argument is of type 'HANDLE' {aka 'void *'}
       640 | rpl_fd_isset (SOCKET fd, fd_set * set)
           |               ~~~~~~~^~

This happens because select.c does:

  HANDLE h, handle_array[FD_SETSIZE + 2];
  ...
      h = (HANDLE) _get_osfhandle (i);
      if (h != handle_array[nhandles])
        {
          /* Perform handle->descriptor mapping.  */
          WSAEventSelect ((SOCKET) h, NULL, 0);
          if (FD_ISSET (h, &handle_rfds))
            FD_SET (i, rfds);
          if (FD_ISSET (h, &handle_wfds))
            FD_SET (i, wfds);
          if (FD_ISSET (h, &handle_xfds))
            FD_SET (i, xfds);
        }

However, FD_ISSET macro on native MS-Windows, and therefore Gnulib's
rpl_fd_isset as well, expect a SOCKET argument:

  static int
  rpl_fd_isset (SOCKET fd, fd_set * set)
  {

Suggested fix:

--- gnulib/import/select.c~     2021-07-03 20:41:11.000000000 +0300
+++ gnulib/import/select.c      2021-07-08 17:05:05.471160600 +0300
@@ -531,11 +531,11 @@ restart:
         {
           /* Perform handle->descriptor mapping.  */
           WSAEventSelect ((SOCKET) h, NULL, 0);
-          if (FD_ISSET (h, &handle_rfds))
+          if (FD_ISSET ((SOCKET) h, &handle_rfds))
             FD_SET (i, rfds);
-          if (FD_ISSET (h, &handle_wfds))
+          if (FD_ISSET ((SOCKET) h, &handle_wfds))
             FD_SET (i, wfds);
-          if (FD_ISSET (h, &handle_xfds))
+          if (FD_ISSET ((SOCKET) h, &handle_xfds))
             FD_SET (i, xfds);
         }
       else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]