Ensure incoming timespec values correctly wrap at nsecs.
authorJeremy Allison <jra@samba.org>
Tue, 14 Sep 2010 21:53:17 +0000 (14:53 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 14 Sep 2010 21:53:17 +0000 (14:53 -0700)
Jeremy.

lib/util/time.c
source3/lib/time.c

index ed3b4f8e301c7c09021ce677cd3fe5395ba48baa..6fbeb9749a1592d120fcad813627fed09dcf8228 100644 (file)
@@ -91,8 +91,15 @@ _PUBLIC_ time_t time_mono(time_t *t)
 
 time_t convert_timespec_to_time_t(struct timespec ts)
 {
+       /* Ensure tv_nsec is less than 1sec. */
+       while (ts.tv_nsec > 1000000000) {
+               ts.tv_sec += 1;
+               ts.tv_nsec -= 1000000000;
+       }
+
        /* 1 ns == 1,000,000,000 - one thousand millionths of a second.
           increment if it's greater than 500 millionth of a second. */
+
        if (ts.tv_nsec > 500000000) {
                return ts.tv_sec + 1;
        }
index fad5d97cb108a30d6534abb4b26da4398ba936d0..eba358f11fdcd11c9d5b21ee5a24575faf552730 100644 (file)
@@ -409,6 +409,10 @@ void round_timespec_to_usec(struct timespec *ts)
 {
        struct timeval tv = convert_timespec_to_timeval(*ts);
        *ts = convert_timeval_to_timespec(tv);
+       while (ts->tv_nsec > 1000000000) {
+               ts->tv_sec += 1;
+               ts->tv_nsec -= 1000000000;
+       }
 }
 
 /****************************************************************************