]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3672] fix biased selection in median cut
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 28 Jun 2020 06:39:28 +0000 (08:39 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 28 Jun 2020 06:39:28 +0000 (08:39 +0200)
bk: 5ef83b20C0U4aqQyHOKWkS-wJ8fjLw

ChangeLog
ntpd/ntp_refclock.c

index eeceaa9f10cb57b56caf561eaab50a81ec861f63..e49745ab70dad2c15f06dd967b961e5ecf675fe6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+---
+* [Bug 3672] fix biased selection in median cut <perlinger@ntp.org>
+
 ---
 (4.2.8p15) 2020/06/23 Released by Harlan Stenn <stenn@ntp.org>
 
index 872f4a05263f1b916129c8176d9b842d16342520..33ffb90ce2319025d95f64cfb9963075554397bf 100644 (file)
@@ -583,7 +583,6 @@ refclock_sample(
 {
        size_t  i, j, k, m, n;
        double  off[MAXSTAGE];
-       double  offset;
 
        /*
         * Copy the raw offsets and sort into ascending order. Don't do
@@ -601,12 +600,16 @@ refclock_sample(
        /*
         * Reject the furthest from the median of the samples until
         * approximately 60 percent of the samples remain.
+        *
+        * [Bug 3672] The elimination is now based on the proper
+        * definition of the median. The true median is not calculated
+        * directly, though.
         */
        i = 0; j = n;
        m = n - (n * 4) / 10;
-       while ((j - i) > m) {
-               offset = off[(j + i) / 2];
-               if (off[j - 1] - offset < offset - off[i])
+       while ((k = j - i) > m) {
+               k = (k - 1) >> 1;
+               if ((off[j - 1] - off[j - k - 1]) < (off[i + k] - off[i]))
                        i++;    /* reject low end */
                else
                        j--;    /* reject high end */