[Openvpn-devel,v8] event: Silence conversion warning in tv_to_ms_timeout

Message ID 20250924145715.28701-1-gert@greenie.muc.de
State New
Headers show
Series [Openvpn-devel,v8] event: Silence conversion warning in tv_to_ms_timeout | expand

Commit Message

Gert Doering Sept. 24, 2025, 2:57 p.m. UTC
From: Frank Lichtenheld <frank@lichtenheld.com>

The APIs want int (at least on unixy systems), so we
use int. max_int() protects us against negative values.

Change-Id: Ie8a242838b6f8b42f36327c33fc62bb5f94ec43f
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: MaxF <max@max-fillinger.net>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
This mail reflects revision 8 of this Change.

Acked-by according to Gerrit (reflected above):
MaxF <max@max-fillinger.net>

Comments

Gert Doering Sept. 24, 2025, 3:05 p.m. UTC | #1
Trivial enough... and ACK from MaxF, so not testing anything beyond 
a quick local compile.

Your patch has been applied to the master branch.

commit da1d0064ae590213f0245125d6974850fecaa943
Author: Frank Lichtenheld
Date:   Wed Sep 24 16:57:09 2025 +0200

     event: Silence conversion warning in tv_to_ms_timeout

     Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
     Acked-by: MaxF <max@max-fillinger.net>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178
     Message-Id: <20250924145715.28701-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33193.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/event.c b/src/openvpn/event.c
index 2f60b78..ca84d19 100644
--- a/src/openvpn/event.c
+++ b/src/openvpn/event.c
@@ -65,11 +65,15 @@ 
 #define SELECT_MAX_FDS 256
 #endif
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
+/** Convert \c timeval value (which is in seconds and microseconds)
+    to a value of milliseconds which is required by multiple polling
+    APIs.
 
+    @param tv \c timeval to convert
+
+    @return Milliseconds to wait. Zero if \p tv is zero.
+     Otherwise the return value is always greater than zero.
+*/
 static inline int
 tv_to_ms_timeout(const struct timeval *tv)
 {
@@ -79,14 +83,11 @@ 
     }
     else
     {
-        return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
+        /* might overflow but not for practically useful numbers */
+        return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
     }
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32
 
 struct we_set