From: Miroslav Lichvar Date: Tue, 10 Jan 2017 16:23:47 +0000 (+0100) Subject: util: handle zero in conversion of NTP timestamps X-Git-Tag: 3.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0f7efd59ea793e4eaf8b8ebe909a34d9282de2a;p=thirdparty%2Fchrony.git util: handle zero in conversion of NTP timestamps 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. --- diff --git a/util.c b/util.c index 0488f010..977580a6 100644 --- 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);