Skip to content

Commit da1d006

Browse files
flichtenheldcron2
authored andcommitted
event: Silence conversion warning in tv_to_ms_timeout
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 <[email protected]> Acked-by: MaxF <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1178 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg33193.html Signed-off-by: Gert Doering <[email protected]>
1 parent 26a4cd6 commit da1d006

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/openvpn/event.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@
6565
#define SELECT_MAX_FDS 256
6666
#endif
6767

68-
#if defined(__GNUC__) || defined(__clang__)
69-
#pragma GCC diagnostic push
70-
#pragma GCC diagnostic ignored "-Wconversion"
71-
#endif
68+
/** Convert \c timeval value (which is in seconds and microseconds)
69+
to a value of milliseconds which is required by multiple polling
70+
APIs.
71+
72+
@param tv \c timeval to convert
7273
74+
@return Milliseconds to wait. Zero if \p tv is zero.
75+
Otherwise the return value is always greater than zero.
76+
*/
7377
static inline int
7478
tv_to_ms_timeout(const struct timeval *tv)
7579
{
@@ -79,14 +83,11 @@ tv_to_ms_timeout(const struct timeval *tv)
7983
}
8084
else
8185
{
82-
return max_int(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000, 1);
86+
/* might overflow but not for practically useful numbers */
87+
return max_int((int)(tv->tv_sec * 1000 + (tv->tv_usec + 500) / 1000), 1);
8388
}
8489
}
8590

86-
#if defined(__GNUC__) || defined(__clang__)
87-
#pragma GCC diagnostic pop
88-
#endif
89-
9091
#ifdef _WIN32
9192

9293
struct we_set

0 commit comments

Comments
 (0)