]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3438] (ntpq) Negative values and values > 999 days in...
authorJuergen Perlinger <perlinger@ntp.org>
Thu, 12 Oct 2017 10:51:50 +0000 (12:51 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Thu, 12 Oct 2017 10:51:50 +0000 (12:51 +0200)
 - make sure negative values are curbed and excessive days are converted to years

bk: 59df4946w6Lo3j46O3tGbqJrmcZqJQ

ChangeLog
ntpq/ntpq-subs.c

index a1a1cfae45a59975bb12958d206f6c0a48e631b5..7578bdb73fa1058fe4a6666cc47fb1b3daeed9d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3438] Negative values and values > 999 days in... <perlinger@ntp.org>
+ - applied patch by ggarvey (with minor mods)
+
 ---
 (4.2.8p10-win-beta1) 2017/03/21 Released by Harlan Stenn <stenn@ntp.org>
 (4.2.8p10)
index 08f9d426a4a476c15ff0d9c250414c48e0e8d650..ed19a15231b0b601789ffec215896e6530d55de4 100644 (file)
@@ -1452,6 +1452,8 @@ when(
        else
                return 0;
 
+       if (ts->l_ui < lasttime->l_ui)
+               return -1;
        return (ts->l_ui - lasttime->l_ui);
 }
 
@@ -1490,7 +1492,14 @@ prettyinterval(
        }
 
        diff = (diff + 11) / 24;
-       snprintf(buf, cb, "%ldd", diff);
+       if (diff <= 999) {
+               snprintf(buf, cb, "%ldd", diff);
+               return buf;
+       }
+
+       /* years are only approximated... */
+       diff = (long)floor(diff / 365.25 + 0.5);
+       snprintf(buf, cb, "%ldy", diff);
        return buf;
 }