ntpd: correct fixed->float conversions of fractions
Need to divide by (1<<32), not by (1<<32)-1.
Fraction of 0xffffffff is not 1 whole second.
function old new delta
.rodata 105264 105268 +4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 4365166..ff49550 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -564,7 +564,7 @@
double ret;
lfp.int_partl = ntohl(lfp.int_partl);
lfp.fractionl = ntohl(lfp.fractionl);
- ret = (double)lfp.int_partl + ((double)lfp.fractionl / UINT_MAX);
+ ret = (double)lfp.int_partl + ((double)lfp.fractionl / (1ULL << 32));
/*
* Shift timestamps before 1970 to the second NTP era (2036-2106):
* int_partl value of OFFSET_1900_1970 (2208988800) is interpreted as
@@ -581,7 +581,7 @@
double ret;
sfp.int_parts = ntohs(sfp.int_parts);
sfp.fractions = ntohs(sfp.fractions);
- ret = (double)sfp.int_parts + ((double)sfp.fractions / USHRT_MAX);
+ ret = (double)sfp.int_parts + ((double)sfp.fractions / (1 << 16));
return ret;
}
#if ENABLE_FEATURE_NTPD_SERVER
@@ -591,7 +591,7 @@
uint32_t intl;
uint32_t frac;
intl = (uint32_t)(time_t)d;
- frac = (uint32_t)((d - (time_t)d) * UINT_MAX);
+ frac = (uint32_t)((d - (time_t)d) * 0xffffffff);
lfp->int_partl = htonl(intl);
lfp->fractionl = htonl(frac);
}
@@ -601,7 +601,7 @@
uint16_t ints;
uint16_t frac;
ints = (uint16_t)d;
- frac = (uint16_t)((d - ints) * USHRT_MAX);
+ frac = (uint16_t)((d - ints) * 0xffff);
sfp->int_parts = htons(ints);
sfp->fractions = htons(frac);
}