From 1597bd6b7c510475f668406037b35b39e186af4f Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Mon, 15 Aug 2016 21:52:05 +0100 Subject: [PATCH] warnings: multiply timeval seconds only when the value is small It should be safe to multiply timeval seconds by million after substracting sequence timestamp from now. The reason to postpone multiply operation is to ensure there is smallest possible change for interger overflow to happen. --- net.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net.c b/net.c index 522f932..c5968c1 100644 --- a/net.c +++ b/net.c @@ -1817,14 +1817,12 @@ void net_process_fds(fd_set *writefd) { int at, fd, r; struct timeval now; - uint64_t unow, utime; /* Can't do MPLS decoding */ struct mplslen mpls; mpls.labels = 0; gettimeofday(&now, NULL); - unow = now.tv_sec * 1000000L + now.tv_usec; for (at = 0; at < MaxSequence; at++) { fd = sequence[at].socket; @@ -1841,8 +1839,9 @@ void net_process_fds(fd_set *writefd) } } if (fd > 0) { - utime = sequence[at].time.tv_sec * 1000000L + sequence[at].time.tv_usec; - if (unow - utime > tcp_timeout) { + struct timeval subtract; + timersub(&now, &sequence[at].time, &subtract); + if ((subtract.tv_sec * 1000000L + subtract.tv_usec) > tcp_timeout) { close(fd); sequence[at].socket = 0; } -- 2.47.2