bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / code / Atom feed
* Missing type cast in select.c
@ 2021-07-08 14:17 Eli Zaretskii
  0 siblings, 0 replies; only message in thread
From: Eli Zaretskii @ 2021-07-08 14:17 UTC (permalink / raw)
  To: bug-gnulib

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-08 14:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 14:17 Missing type cast in select.c Eli Zaretskii

Code repositories for project(s) associated with this inbox:

	../../../mirrors/gnulib.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).