From: Harlan Stenn Date: Sat, 18 Feb 2006 04:50:33 +0000 (-0500) Subject: Only fuzz the time after we know sys_precision (gettimeofday only) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6c4b52812ffb6d60f21e6a5ffb7a9f8d364fa37;p=thirdparty%2Fntp.git Only fuzz the time after we know sys_precision (gettimeofday only) bk: 43f6a799NOzMrZGDBW6R1qzgPUXIvg --- diff --git a/libntp/systime.c b/libntp/systime.c index 711a540089..05f47c65c7 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -81,8 +81,16 @@ get_systime( */ GETTIMEOFDAY(&tv, NULL); now->l_i = tv.tv_sec + JAN_1970; - /* ntp_random() produces 31 bits (always nonnegative) */ - dtemp = (tv.tv_usec + ntp_random() / FRAC - .5) / 1e6; + dtemp = ts.tv_nsec / 1e6; + + /* + * ntp_random() produces 31 bits (always nonnegative. + * This bit is done only after the precision has been + * determined. + */ + if (sys_precision != 0) + dtemp += (ntp_random() / FRAC - .5) / (1 << + -sys_precision); #endif /* HAVE_CLOCK_GETTIME || HAVE_GETCLOCK */