[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] tv_udiff: do not modify arguments, and compute results corr...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] tv_udiff: do not modify arguments, and compute results corr...
- From: nickm@seul.org (Nick Mathewson)
- Date: Wed, 16 Apr 2003 21:59:44 -0400 (EDT)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Wed, 16 Apr 2003 21:59:51 -0400
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv24248/src/common
Modified Files:
util.c
Log Message:
tv_udiff: do not modify arguments, and compute results correctly.
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- util.c 16 Apr 2003 23:22:05 -0000 1.2
+++ util.c 17 Apr 2003 01:59:41 -0000 1.3
@@ -23,16 +23,18 @@
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;