Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.busybox.net/busybox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-01-17 19:01:05 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2023-01-17 19:01:05 +0300
commitc344ca6c7f5d8468624ae518d2912d1d9612cb91 (patch)
treebb8e3940c8914fc3ddacc7b7b571545fe7cfc233 /networking
parent85acf71d2579ebe4eec05c6f31901adffa700adc (diff)
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>
Diffstat (limited to 'networking')
-rw-r--r--networking/ntpd.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 4365166ff..ff49550e9 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -564,7 +564,7 @@ lfp_to_d(l_fixedpt_t lfp)
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 @@ sfp_to_d(s_fixedpt_t sfp)
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 @@ d_to_lfp(l_fixedpt_t *lfp, double d)
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 @@ d_to_sfp(s_fixedpt_t *sfp, double d)
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);
}