[Git][NTPsec/ntpsec][master] Forward-port from Classic: [Bug 2772] adj_systime overflows tv_usec
Eric S. Raymond
gitlab at mg.gitlab.com
Sun Mar 20 20:35:53 UTC 2016
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
f6c75ecc by Juergen Perlinger at 2016-03-20T16:34:39-04:00
Forward-port from Classic: [Bug 2772] adj_systime overflows tv_usec
- - - - -
1 changed file:
- libntp/systime.c
Changes:
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -312,9 +312,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
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f6c75eccfe9a2e2d7a9bc56063768e5d3d4ed590
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160320/6c31a960/attachment.html>
More information about the vc
mailing list