]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: fix UTI_FloatNetworkToHost() with very small exponents
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 17 Mar 2016 13:28:45 +0000 (14:28 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 17 Mar 2016 15:18:28 +0000 (16:18 +0100)
Fix conversion of floating point numbers from the cmdmon format with
very small exponents, as for instance could be in the smoothing report
when the smoothing process ends.

This was broken in commit 8e71a46173afe01e11620980a1c7c028d7fd048f.

util.c

diff --git a/util.c b/util.c
index b654e632ddafd851988931ea6aef6eccc4738bf8..9085ff6b2436eab54e85fdd6b15e8a753ed2fb1b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -807,9 +807,10 @@ UTI_FloatNetworkToHost(Float f)
 
   x = ntohl(f.f);
 
-  exp = (x >> FLOAT_COEF_BITS) - FLOAT_COEF_BITS;
+  exp = x >> FLOAT_COEF_BITS;
   if (exp >= 1 << (FLOAT_EXP_BITS - 1))
       exp -= 1 << FLOAT_EXP_BITS;
+  exp -= FLOAT_COEF_BITS;
 
   coef = x % (1U << FLOAT_COEF_BITS);
   if (coef >= 1 << (FLOAT_COEF_BITS - 1))