Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2390?usp=email

to review the following change.


Change subject: Avoid sign conversion warnings related to FD_* in musl
......................................................................

Avoid sign conversion warnings related to FD_* in musl

In musl FD_* do unsigned operations of the operand
without casting. glibc uses explicit casting where
required. Cast the operands to an unsigned value
so that both libraries are happy.

The surrounding code already ensures that the
fd is non-negative, so this is safe.

This does not work on Windows, but most of the
code is guarded by #if SELECT, which is non-Windows
anyway.

Change-Id: I237e59c490fb50003f207b56c743429f78fc4b8e
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/event.c
M src/openvpn/fdmisc.h
2 files changed, 15 insertions(+), 19 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/90/2390/1

diff --git a/src/openvpn/event.c b/src/openvpn/event.c
index c4a856d..06df285 100644
--- a/src/openvpn/event.c
+++ b/src/openvpn/event.c
@@ -964,8 +964,8 @@
 
     if (event >= 0 && event < ses->capacity)
     {
-        FD_CLR(event, &ses->readfds);
-        FD_CLR(event, &ses->writefds);
+        FD_CLR((unsigned int)event, &ses->readfds);
+        FD_CLR((unsigned int)event, &ses->writefds);
         ses->args[event] = NULL;
     }
     else
@@ -1006,7 +1006,7 @@
             }
             else
             {
-                FD_CLR(event, &ses->readfds);
+                FD_CLR((unsigned int)event, &ses->readfds);
             }
             if (rwflags & EVENT_WRITE)
             {
@@ -1014,7 +1014,7 @@
             }
             else
             {
-                FD_CLR(event, &ses->writefds);
+                FD_CLR((unsigned int)event, &ses->writefds);
             }
         }
     }
@@ -1029,11 +1029,11 @@
 se_wait_return(struct se_set *ses, const fd_set *read, const fd_set *write, 
struct event_set_return *out,
                int outlen)
 {
-    int i, j = 0;
-    for (i = 0; i <= ses->maxfd && j < outlen; ++i)
+    int j = 0;
+    for (int i = 0; i <= ses->maxfd && j < outlen; ++i)
     {
-        const bool r = FD_ISSET(i, read);
-        const bool w = FD_ISSET(i, write);
+        const bool r = FD_ISSET((unsigned int)i, read);
+        const bool w = FD_ISSET((unsigned int)i, write);
         if (r || w)
         {
             out->rwflags = 0;
diff --git a/src/openvpn/fdmisc.h b/src/openvpn/fdmisc.h
index 15ee3cd..732427b 100644
--- a/src/openvpn/fdmisc.h
+++ b/src/openvpn/fdmisc.h
@@ -35,23 +35,19 @@

 void set_cloexec(socket_descriptor_t fd);

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 static inline void
 openvpn_fd_set(socket_descriptor_t fd, fd_set *setp)
 {
 #ifndef _WIN32 /* The Windows FD_SET() implementation does not overflow */
     ASSERT(fd >= 0 && fd < FD_SETSIZE);
-#endif
+    /* fd is known to be non-negative here; the cast avoids
+     * -Wsign-conversion with libc implementations (e.g. musl)
+     * whose FD_SET() does unsigned arithmetic on the descriptor */
+    FD_SET((unsigned int)fd, setp);
+#else
     FD_SET(fd, setp);
+#endif
 }
 #undef FD_SET /* prevent direct use of FD_SET() */

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
-#endif /* FD_MISC_H */
+#endif        /* FD_MISC_H */

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2390?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I237e59c490fb50003f207b56c743429f78fc4b8e
Gerrit-Change-Number: 2390
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to