From: Sami Kerola Date: Mon, 15 Aug 2016 20:52:05 +0000 (+0100) Subject: warnings: multiply timeval seconds only when the value is small X-Git-Tag: v0.88~38^2~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F135%2Fhead;p=thirdparty%2Fmtr.git 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. --- 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; }