Commit 1fef22a2 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Protect against overflow in timeval_minus_msec.

This would cause an infinite loop when the clock was stepped.
parent 03a700eb
......@@ -79,6 +79,12 @@ timeval_minus(struct timeval *d,
int
timeval_minus_msec(const struct timeval *s1, const struct timeval *s2)
{
/* Avoid overflow. This may happen if the clock is changed */
if(s1->tv_sec - s2->tv_sec > 2000000)
return 2000000000;
else if(s1->tv_sec - s2->tv_sec < -2000000)
return -2000000000;
return (s1->tv_sec - s2->tv_sec) * 1000 +
(s1->tv_usec - s2->tv_usec) / 1000;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment