|
@@ -1386,7 +1386,7 @@ tv_udiff(const struct timeval *start, const struct timeval *end)
|
|
|
long udiff;
|
|
|
long secdiff = end->tv_sec - start->tv_sec;
|
|
|
|
|
|
- if (labs(secdiff+1) > LONG_MAX/1000000) {
|
|
|
+ if (labs(secdiff)+1 > LONG_MAX/1000000) {
|
|
|
log_warn(LD_GENERAL, "comparing times on microsecond detail too far "
|
|
|
"apart: %ld seconds", secdiff);
|
|
|
return LONG_MAX;
|
|
@@ -1404,7 +1404,7 @@ tv_mdiff(const struct timeval *start, const struct timeval *end)
|
|
|
long mdiff;
|
|
|
long secdiff = end->tv_sec - start->tv_sec;
|
|
|
|
|
|
- if (labs(secdiff+1) > LONG_MAX/1000) {
|
|
|
+ if (labs(secdiff)+1 > LONG_MAX/1000) {
|
|
|
log_warn(LD_GENERAL, "comparing times on millisecond detail too far "
|
|
|
"apart: %ld seconds", secdiff);
|
|
|
return LONG_MAX;
|
|
@@ -1412,7 +1412,13 @@ tv_mdiff(const struct timeval *start, const struct timeval *end)
|
|
|
|
|
|
|
|
|
mdiff = secdiff*1000L +
|
|
|
- ((long)end->tv_usec - (long)start->tv_usec + 500L) / 1000L;
|
|
|
+
|
|
|
+ * so that the round-towards-zero behavior of the division will give
|
|
|
+ * the right result for rounding to the nearest msec. Later we subtract
|
|
|
+ * 1000 in order to get the correct result.
|
|
|
+ */
|
|
|
+ ((long)end->tv_usec - (long)start->tv_usec + 500L + 1000000L) / 1000L
|
|
|
+ - 1000;
|
|
|
return mdiff;
|
|
|
}
|
|
|
|