mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
tv_udiff: do not modify arguments, and compute results correctly.
svn:r245
This commit is contained in:
parent
0a9e83369a
commit
2da6482f63
@ -23,16 +23,18 @@ long
|
|||||||
tv_udiff(struct timeval *start, struct timeval *end)
|
tv_udiff(struct timeval *start, struct timeval *end)
|
||||||
{
|
{
|
||||||
long udiff;
|
long udiff;
|
||||||
|
long end_usec = end->tv_usec;
|
||||||
long secdiff = end->tv_sec - start->tv_sec;
|
long secdiff = end->tv_sec - start->tv_sec;
|
||||||
|
|
||||||
if (secdiff+1 > LONG_MAX/1000000) {
|
if (secdiff+1 > LONG_MAX/1000000) {
|
||||||
log(LOG_NOTICE, "tv_udiff(): comparing times too far apart.");
|
log(LOG_NOTICE, "tv_udiff(): comparing times too far apart.");
|
||||||
return LONG_MAX;
|
return LONG_MAX;
|
||||||
}
|
}
|
||||||
if (end->tv_usec < start->tv_usec) {
|
if (end_usec < start->tv_usec) {
|
||||||
end->tv_sec--;
|
secdiff--;
|
||||||
end->tv_usec += 1000000L;
|
end_usec += 1000000L;
|
||||||
}
|
}
|
||||||
udiff = secdiff*1000000L + (end->tv_usec - start->tv_usec);
|
udiff = secdiff*1000000L + (end_usec - start->tv_usec);
|
||||||
if(udiff < 0) {
|
if(udiff < 0) {
|
||||||
log(LOG_NOTICE, "tv_udiff(): start is after end. Returning 0.");
|
log(LOG_NOTICE, "tv_udiff(): start is after end. Returning 0.");
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user