]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Alter the "ci" calculation to reduce the chance of overflow.
authorHarlan Stenn <stenn@ntp.org>
Thu, 13 Dec 2001 02:46:20 +0000 (21:46 -0500)
committerHarlan Stenn <stenn@ntp.org>
Thu, 13 Dec 2001 02:46:20 +0000 (21:46 -0500)
From: Michael Andres <ma@suse.de>

bk: 3c18167cbDtnMDDOCrpcZ6FjENudXw

ntpdate/ntpdate.c

index 8a5b00a95df47ba42b8fbb123adae89faabca91e..f3db8867fcb5c9b87c378832f3990f640f285ce9 100644 (file)
@@ -740,7 +740,7 @@ receive(
        register struct pkt *rpkt;
        register struct server *server;
        register s_fp di;
-       l_fp t10, t23;
+       l_fp t10, t23, tmp;
        l_fp org;
        l_fp rec;
        l_fp ci;
@@ -862,9 +862,15 @@ receive(
        L_SUB(&t23, &org);              /* pkt->org == t3 */
 
        /* now have (t2 - t3) and (t0 - t1).    Calculate (ci) and (di) */
+       /*
+        * Calculate (ci) = ((t1 - t0) / 2) + ((t2 - t3) / 2)
+        * For large offsets this may prevent an overflow on '+'
+        */
        ci = t10;
-       L_ADD(&ci, &t23);
        L_RSHIFT(&ci);
+       tmp = t23;
+       L_RSHIFT(&tmp);
+       L_ADD(&ci, &tmp);
 
        /*
         * Calculate di in t23 in full precision, then truncate