aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-04-17 01:59:41 +0000
committerNick Mathewson <nickm@torproject.org>2003-04-17 01:59:41 +0000
commit2da6482f639871784b445187347314e8d026bdb1 (patch)
tree8234a8daacbe5ea9b97b7735e16d389fc94191c5 /src
parent0a9e83369ad3610bef9b136e431ff42a86888af0 (diff)
downloadtor-2da6482f639871784b445187347314e8d026bdb1.tar
tor-2da6482f639871784b445187347314e8d026bdb1.tar.gz
tv_udiff: do not modify arguments, and compute results correctly.
svn:r245
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 743df0bbb..600a8e614 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -23,16 +23,18 @@ long
tv_udiff(struct timeval *start, struct timeval *end)
{
long udiff;
+ long end_usec = end->tv_usec;
long secdiff = end->tv_sec - start->tv_sec;
+
if (secdiff+1 > LONG_MAX/1000000) {
log(LOG_NOTICE, "tv_udiff(): comparing times too far apart.");
return LONG_MAX;
}
- if (end->tv_usec < start->tv_usec) {
- end->tv_sec--;
- end->tv_usec += 1000000L;
+ if (end_usec < start->tv_usec) {
+ secdiff--;
+ end_usec += 1000000L;
}
- udiff = secdiff*1000000L + (end->tv_usec - start->tv_usec);
+ udiff = secdiff*1000000L + (end_usec - start->tv_usec);
if(udiff < 0) {
log(LOG_NOTICE, "tv_udiff(): start is after end. Returning 0.");
return 0;