]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: handle zero in conversion of NTP timestamps
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 10 Jan 2017 16:23:47 +0000 (17:23 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 12 Jan 2017 15:34:28 +0000 (16:34 +0100)
Handle zero NTP timestamp in UTI_Ntp64ToTimespec() as a special value to
make it symmetric with UTI_TimespecToNtp64(). This is needed since
commit d75f6830f190037421a66754849571fd0b495e35, in which a timestamp is
converted back and forth without checking for zero.

It also makes zero NTP timestamps more apparent in debug output.

util.c

diff --git a/util.c b/util.c
index 0488f0105fe3e077006db8352baf980ba2ee42c4..977580a6edade004595de3a4ab6fac5bb16293e3 100644 (file)
--- a/util.c
+++ b/util.c
@@ -754,8 +754,11 @@ UTI_Ntp64ToTimespec(NTP_int64 *src, struct timespec *dest)
 {
   uint32_t ntp_sec, ntp_frac;
 
-  /* As yet, there is no need to check for zero - all processing that
-     has to detect that case is in the NTP layer */
+  /* Zero is a special value */
+  if (UTI_IsZeroNtp64(src)) {
+    UTI_ZeroTimespec(dest);
+    return;
+  }
 
   ntp_sec = ntohl(src->hi);
   ntp_frac = ntohl(src->lo);