]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
warnings: multiply timeval seconds only when the value is small 135/head
authorSami Kerola <kerolasa@iki.fi>
Mon, 15 Aug 2016 20:52:05 +0000 (21:52 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 15 Aug 2016 20:56:15 +0000 (21:56 +0100)
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

diff --git a/net.c b/net.c
index 522f932fc1e7456c655fe0ea20cbb34ee91ade05..c5968c10b81520f787326e44846c7e202e6ec4cb 100644 (file)
--- 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;
       }