summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/systime.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp/systime.c')
-rw-r--r--contrib/ntp/libntp/systime.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/contrib/ntp/libntp/systime.c b/contrib/ntp/libntp/systime.c
index c89d157..29f1e86 100644
--- a/contrib/ntp/libntp/systime.c
+++ b/contrib/ntp/libntp/systime.c
@@ -323,9 +323,18 @@ adj_systime(
else
quant = 1e-6;
ticks = (long)(dtemp / quant + .5);
- adjtv.tv_usec = (long)(ticks * quant * 1e6);
- dtemp -= adjtv.tv_usec / 1e6;
- sys_residual = dtemp;
+ adjtv.tv_usec = (long)(ticks * quant * 1.e6 + .5);
+ /* The rounding in the conversions could us push over the
+ * limits: make sure the result is properly normalised!
+ * note: sign comes later, all numbers non-negative here.
+ */
+ if (adjtv.tv_usec >= 1000000) {
+ adjtv.tv_sec += 1;
+ adjtv.tv_usec -= 1000000;
+ dtemp -= 1.;
+ }
+ /* set the new residual with leftover from correction */
+ sys_residual = dtemp - adjtv.tv_usec * 1.e-6;
/*
* Convert to signed seconds and microseconds for the Unix
OpenPOWER on IntegriCloud