From: Juergen Perlinger Date: Sun, 23 Jan 2011 11:08:42 +0000 (+0100) Subject: [Bug 1788] tables in libntp/tvtots.c imprecise X-Git-Tag: NTP_4_2_7P123~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1247eca11d3f2c48efa31f8d2d2c0a19914a4367;p=thirdparty%2Fntp.git [Bug 1788] tables in libntp/tvtots.c imprecise bk: 4d3c0c3atS7k_TseltfDfNSo0Fe0Tw --- diff --git a/ChangeLog b/ChangeLog index b76362553..61a514e35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* [Bug 1788] tvtots.c tables inaccurate (4.2.7p122) 2011/01/22 Released by Harlan Stenn * ACTS refclock cleanup from Dave Mills. * Avoid shadowing the "group" global variable. diff --git a/clockstuff/chutest.c b/clockstuff/chutest.c index 632ab2f15..e5ec554f9 100644 --- a/clockstuff/chutest.c +++ b/clockstuff/chutest.c @@ -72,10 +72,6 @@ int usechuldisc = 0; /* set to 1 when CHU line discipline should be used */ struct timeval lasttv; struct chucode chudata; -extern u_long ustotslo[]; -extern u_long ustotsmid[]; -extern u_long ustotshi[]; - void error(char *fmt, char *s1, char *s2); void init_chu(void); int openterm(char *dev); @@ -513,14 +509,6 @@ static u_long yearstart; extern u_long current_time; extern struct event timerqueue[]; -/* - * Time conversion tables imported from the library - */ -extern u_long ustotslo[]; -extern u_long ustotsmid[]; -extern u_long ustotshi[]; - - /* * init_chu - initialize internal chu driver data */ diff --git a/clockstuff/clktest.c b/clockstuff/clktest.c index 5bd6ae0d9..f254edb66 100644 --- a/clockstuff/clktest.c +++ b/clockstuff/clktest.c @@ -85,10 +85,6 @@ volatile int iosig; struct timeval lasttv; -extern u_long ustotslo[]; -extern u_long ustotsmid[]; -extern u_long ustotshi[]; - int alarming(); int ioready(); diff --git a/include/ntp_unixtime.h b/include/ntp_unixtime.h index a4ba7d7fe..b85f4bb63 100644 --- a/include/ntp_unixtime.h +++ b/include/ntp_unixtime.h @@ -59,9 +59,9 @@ int getclock (int clock_type, struct timespec *tp); * Convert usec to a time stamp fraction. If you use this the program * must include the following declarations: */ -extern u_long ustotslo[]; -extern u_long ustotsmid[]; -extern u_long ustotshi[]; +extern const u_int32 ustotslo[]; +extern const u_int32 ustotsmid[]; +extern const u_int32 ustotshi[]; #define TVUTOTSF(tvu, tsf) \ (tsf) = ustotslo[(tvu) & 0xff] \ @@ -106,9 +106,9 @@ extern u_long ustotshi[]; * Convert a time stamp fraction to microseconds. The time stamp * fraction is assumed to be unsigned. To use this in a program, declare: */ -extern long tstouslo[]; -extern long tstousmid[]; -extern long tstoushi[]; +extern const u_int32 tstouslo[]; +extern const u_int32 tstousmid[]; +extern const u_int32 tstoushi[]; #define TSFTOTVU(tsf, tvu) \ (tvu) = (tstoushi[((tsf) >> 24) & 0xff] \ @@ -134,8 +134,8 @@ extern long tstoushi[]; * here, but it is convenient since the guys who use the definition will * often be including this file anyway. */ -extern u_long msutotsflo[]; -extern u_long msutotsfhi[]; +extern const u_int32 msutotsflo[]; +extern const u_int32 msutotsfhi[]; #define MSUTOTSF(msu, tsf) \ (tsf) = msutotsfhi[((msu) >> 5) & 0x1f] + msutotsflo[(msu) & 0x1f] diff --git a/libntp/msutotsf.c b/libntp/msutotsf.c index 2182d9f26..22ae6119b 100644 --- a/libntp/msutotsf.c +++ b/libntp/msutotsf.c @@ -13,7 +13,7 @@ * truncated). The error in the result will thus be +-1 low order * bit in the time stamp fraction. */ -u_long msutotsflo[32] = { +const u_int32 msutotsflo[32] = { 0x00000000, 0x00418937, 0x0083126f, 0x00c49ba6, 0x010624dd, 0x0147ae14, 0x0189374c, 0x01cac083, 0x020c49ba, 0x024dd2f2, 0x028f5c29, 0x02d0e560, @@ -24,7 +24,7 @@ u_long msutotsflo[32] = { 0x072b020c, 0x076c8b44, 0x07ae147b, 0x07ef9db2 }; -u_long msutotsfhi[32] = { +const u_int32 msutotsfhi[32] = { 0x00000000, 0x083126e9, 0x10624dd3, 0x189374bc, 0x20c49ba6, 0x28f5c28f, 0x3126e979, 0x39581062, 0x4189374c, 0x49ba5e35, 0x51eb851f, 0x5a1cac08, diff --git a/libntp/tstotv.c b/libntp/tstotv.c index 278dadfd0..664bf127b 100644 --- a/libntp/tstotv.c +++ b/libntp/tstotv.c @@ -14,7 +14,7 @@ * These tables are rounded. */ -long tstoushi[256] = { +const u_int32 tstoushi[256] = { 0x000000, 0x007a12, 0x00f424, 0x016e36, 0x01e848, 0x02625a, 0x02dc6c, 0x03567e, 0x03d090, 0x044aa2, 0x04c4b4, 0x053ec6, @@ -81,7 +81,7 @@ long tstoushi[256] = { 0x7829b8, 0x78a3ca, 0x791ddc, 0x7997ee }; -long tstousmid[256] = { +const u_int32 tstousmid[256] = { 0x0000, 0x007a, 0x00f4, 0x016e, 0x01e8, 0x0262, 0x02dc, 0x0356, 0x03d1, 0x044b, 0x04c5, 0x053f, 0x05b9, 0x0633, 0x06ad, 0x0727, 0x07a1, 0x081b, 0x0895, 0x090f, 0x0989, 0x0a03, 0x0a7e, 0x0af8, @@ -116,7 +116,7 @@ long tstousmid[256] = { 0x7641, 0x76bc, 0x7736, 0x77b0, 0x782a, 0x78a4, 0x791e, 0x7998 }; -long tstouslo[128] = { +const u_int32 tstouslo[128] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, diff --git a/libntp/tvtots.c b/libntp/tvtots.c index 3983e28f1..550c648e7 100644 --- a/libntp/tvtots.c +++ b/libntp/tvtots.c @@ -1,6 +1,6 @@ /* * tvtots - tables for converting from Unix struct timeval's to - * NTP time stamp format. + * NTP time stamp format. */ #include #include @@ -18,7 +18,7 @@ * +- 1.5 low order bits. */ -u_long ustotslo[256] = { +const u_int32 ustotslo[256] = { 0x00000000, 0x000010c7, 0x0000218e, 0x00003255, 0x0000431c, 0x000053e3, 0x000064aa, 0x00007571, 0x00008638, 0x000096ff, 0x0000a7c6, 0x0000b88d, @@ -45,7 +45,7 @@ u_long ustotslo[256] = { 0x00060781, 0x00061848, 0x0006290f, 0x000639d6, 0x00064a9d, 0x00065b64, 0x00066c2b, 0x00067cf2, 0x00068db9, 0x00069e80, 0x0006af47, 0x0006c00e, - 0x0006d0d5, 0x0006e19c, 0x0006f263, 0x00070329, + 0x0006d0d5, 0x0006e19c, 0x0006f263, 0x0007032a, 0x000713f0, 0x000724b7, 0x0007357e, 0x00074645, 0x0007570c, 0x000767d3, 0x0007789a, 0x00078961, 0x00079a28, 0x0007aaef, 0x0007bbb6, 0x0007cc7d, @@ -61,7 +61,7 @@ u_long ustotslo[256] = { 0x000a393f, 0x000a4a06, 0x000a5acd, 0x000a6b94, 0x000a7c5b, 0x000a8d22, 0x000a9de9, 0x000aaeb0, 0x000abf77, 0x000ad03e, 0x000ae105, 0x000af1cc, - 0x000b0292, 0x000b1359, 0x000b2420, 0x000b34e7, + 0x000b0293, 0x000b1359, 0x000b2420, 0x000b34e7, 0x000b45ae, 0x000b5675, 0x000b673c, 0x000b7803, 0x000b88ca, 0x000b9991, 0x000baa58, 0x000bbb1f, 0x000bcbe6, 0x000bdcad, 0x000bed74, 0x000bfe3b, @@ -76,85 +76,85 @@ u_long ustotslo[256] = { 0x000e27e1, 0x000e38a8, 0x000e496f, 0x000e5a36, 0x000e6afd, 0x000e7bc4, 0x000e8c8b, 0x000e9d52, 0x000eae19, 0x000ebee0, 0x000ecfa7, 0x000ee06e, - 0x000ef135, 0x000f01fb, 0x000f12c2, 0x000f2389, + 0x000ef135, 0x000f01fc, 0x000f12c2, 0x000f2389, 0x000f3450, 0x000f4517, 0x000f55de, 0x000f66a5, 0x000f776c, 0x000f8833, 0x000f98fa, 0x000fa9c1, 0x000fba88, 0x000fcb4f, 0x000fdc16, 0x000fecdd, 0x000ffda4, 0x00100e6b, 0x00101f32, 0x00102ff9, 0x001040c0, 0x00105187, 0x0010624e, 0x00107315, - 0x001083dc, 0x001094a3, 0x0010a56a, 0x0010b631, + 0x001083dc, 0x001094a3, 0x0010a56a, 0x0010b631 }; -u_long ustotsmid[256] = { +const u_int32 ustotsmid[256] = { 0x00000000, 0x0010c6f8, 0x00218def, 0x003254e7, - 0x00431bde, 0x0053e2d6, 0x0064a9ce, 0x007570c5, - 0x008637bd, 0x0096feb4, 0x00a7c5ac, 0x00b88ca4, - 0x00c9539b, 0x00da1a93, 0x00eae18a, 0x00fba882, - 0x010c6f7a, 0x011d3671, 0x012dfd69, 0x013ec460, - 0x014f8b58, 0x01605250, 0x01711947, 0x0181e03f, - 0x0192a736, 0x01a36e2e, 0x01b43526, 0x01c4fc1d, - 0x01d5c315, 0x01e68a0c, 0x01f75104, 0x020817fc, - 0x0218def3, 0x0229a5eb, 0x023a6ce3, 0x024b33da, - 0x025bfad2, 0x026cc1c9, 0x027d88c1, 0x028e4fb9, - 0x029f16b0, 0x02afdda8, 0x02c0a49f, 0x02d16b97, - 0x02e2328f, 0x02f2f986, 0x0303c07e, 0x03148775, - 0x03254e6d, 0x03361565, 0x0346dc5c, 0x0357a354, - 0x03686a4b, 0x03793143, 0x0389f83b, 0x039abf32, - 0x03ab862a, 0x03bc4d21, 0x03cd1419, 0x03dddb11, - 0x03eea208, 0x03ff6900, 0x04102ff7, 0x0420f6ef, - 0x0431bde7, 0x044284de, 0x04534bd6, 0x046412cd, - 0x0474d9c5, 0x0485a0bd, 0x049667b4, 0x04a72eac, - 0x04b7f5a3, 0x04c8bc9b, 0x04d98393, 0x04ea4a8a, - 0x04fb1182, 0x050bd879, 0x051c9f71, 0x052d6669, - 0x053e2d60, 0x054ef458, 0x055fbb4f, 0x05708247, - 0x0581493f, 0x05921036, 0x05a2d72e, 0x05b39e25, - 0x05c4651d, 0x05d52c15, 0x05e5f30c, 0x05f6ba04, - 0x060780fb, 0x061847f3, 0x06290eeb, 0x0639d5e2, - 0x064a9cda, 0x065b63d2, 0x066c2ac9, 0x067cf1c1, - 0x068db8b8, 0x069e7fb0, 0x06af46a8, 0x06c00d9f, - 0x06d0d497, 0x06e19b8e, 0x06f26286, 0x0703297e, - 0x0713f075, 0x0724b76d, 0x07357e64, 0x0746455c, - 0x07570c54, 0x0767d34b, 0x07789a43, 0x0789613a, - 0x079a2832, 0x07aaef2a, 0x07bbb621, 0x07cc7d19, - 0x07dd4410, 0x07ee0b08, 0x07fed200, 0x080f98f7, - 0x08205fef, 0x083126e6, 0x0841edde, 0x0852b4d6, - 0x08637bcd, 0x087442c5, 0x088509bc, 0x0895d0b4, - 0x08a697ac, 0x08b75ea3, 0x08c8259b, 0x08d8ec92, - 0x08e9b38a, 0x08fa7a82, 0x090b4179, 0x091c0871, - 0x092ccf68, 0x093d9660, 0x094e5d58, 0x095f244f, - 0x096feb47, 0x0980b23e, 0x09917936, 0x09a2402e, - 0x09b30725, 0x09c3ce1d, 0x09d49514, 0x09e55c0c, - 0x09f62304, 0x0a06e9fb, 0x0a17b0f3, 0x0a2877ea, - 0x0a393ee2, 0x0a4a05da, 0x0a5accd1, 0x0a6b93c9, - 0x0a7c5ac1, 0x0a8d21b8, 0x0a9de8b0, 0x0aaeafa7, - 0x0abf769f, 0x0ad03d97, 0x0ae1048e, 0x0af1cb86, - 0x0b02927d, 0x0b135975, 0x0b24206d, 0x0b34e764, - 0x0b45ae5c, 0x0b567553, 0x0b673c4b, 0x0b780343, - 0x0b88ca3a, 0x0b999132, 0x0baa5829, 0x0bbb1f21, - 0x0bcbe619, 0x0bdcad10, 0x0bed7408, 0x0bfe3aff, - 0x0c0f01f7, 0x0c1fc8ef, 0x0c308fe6, 0x0c4156de, - 0x0c521dd5, 0x0c62e4cd, 0x0c73abc5, 0x0c8472bc, - 0x0c9539b4, 0x0ca600ab, 0x0cb6c7a3, 0x0cc78e9b, - 0x0cd85592, 0x0ce91c8a, 0x0cf9e381, 0x0d0aaa79, - 0x0d1b7171, 0x0d2c3868, 0x0d3cff60, 0x0d4dc657, - 0x0d5e8d4f, 0x0d6f5447, 0x0d801b3e, 0x0d90e236, - 0x0da1a92d, 0x0db27025, 0x0dc3371d, 0x0dd3fe14, - 0x0de4c50c, 0x0df58c03, 0x0e0652fb, 0x0e1719f3, - 0x0e27e0ea, 0x0e38a7e2, 0x0e496ed9, 0x0e5a35d1, - 0x0e6afcc9, 0x0e7bc3c0, 0x0e8c8ab8, 0x0e9d51b0, - 0x0eae18a7, 0x0ebedf9f, 0x0ecfa696, 0x0ee06d8e, - 0x0ef13486, 0x0f01fb7d, 0x0f12c275, 0x0f23896c, - 0x0f345064, 0x0f45175c, 0x0f55de53, 0x0f66a54b, - 0x0f776c42, 0x0f88333a, 0x0f98fa32, 0x0fa9c129, - 0x0fba8821, 0x0fcb4f18, 0x0fdc1610, 0x0fecdd08, - 0x0ffda3ff, 0x100e6af7, 0x101f31ee, 0x102ff8e6, - 0x1040bfde, 0x105186d5, 0x10624dcd, 0x107314c4, - 0x1083dbbc, 0x1094a2b4, 0x10a569ab, 0x10b630a3, + 0x00431bdf, 0x0053e2d6, 0x0064a9ce, 0x007570c5, + 0x008637bd, 0x0096feb5, 0x00a7c5ac, 0x00b88ca4, + 0x00c9539c, 0x00da1a93, 0x00eae18b, 0x00fba882, + 0x010c6f7a, 0x011d3672, 0x012dfd69, 0x013ec461, + 0x014f8b59, 0x01605250, 0x01711948, 0x0181e03f, + 0x0192a737, 0x01a36e2f, 0x01b43526, 0x01c4fc1e, + 0x01d5c316, 0x01e68a0d, 0x01f75105, 0x020817fc, + 0x0218def4, 0x0229a5ec, 0x023a6ce3, 0x024b33db, + 0x025bfad3, 0x026cc1ca, 0x027d88c2, 0x028e4fb9, + 0x029f16b1, 0x02afdda9, 0x02c0a4a0, 0x02d16b98, + 0x02e23290, 0x02f2f987, 0x0303c07f, 0x03148777, + 0x03254e6e, 0x03361566, 0x0346dc5d, 0x0357a355, + 0x03686a4d, 0x03793144, 0x0389f83c, 0x039abf34, + 0x03ab862b, 0x03bc4d23, 0x03cd141a, 0x03dddb12, + 0x03eea20a, 0x03ff6901, 0x04102ff9, 0x0420f6f1, + 0x0431bde8, 0x044284e0, 0x04534bd7, 0x046412cf, + 0x0474d9c7, 0x0485a0be, 0x049667b6, 0x04a72eae, + 0x04b7f5a5, 0x04c8bc9d, 0x04d98394, 0x04ea4a8c, + 0x04fb1184, 0x050bd87b, 0x051c9f73, 0x052d666b, + 0x053e2d62, 0x054ef45a, 0x055fbb51, 0x05708249, + 0x05814941, 0x05921038, 0x05a2d730, 0x05b39e28, + 0x05c4651f, 0x05d52c17, 0x05e5f30e, 0x05f6ba06, + 0x060780fe, 0x061847f5, 0x06290eed, 0x0639d5e5, + 0x064a9cdc, 0x065b63d4, 0x066c2acc, 0x067cf1c3, + 0x068db8bb, 0x069e7fb2, 0x06af46aa, 0x06c00da2, + 0x06d0d499, 0x06e19b91, 0x06f26289, 0x07032980, + 0x0713f078, 0x0724b76f, 0x07357e67, 0x0746455f, + 0x07570c56, 0x0767d34e, 0x07789a46, 0x0789613d, + 0x079a2835, 0x07aaef2c, 0x07bbb624, 0x07cc7d1c, + 0x07dd4413, 0x07ee0b0b, 0x07fed203, 0x080f98fa, + 0x08205ff2, 0x083126e9, 0x0841ede1, 0x0852b4d9, + 0x08637bd0, 0x087442c8, 0x088509c0, 0x0895d0b7, + 0x08a697af, 0x08b75ea6, 0x08c8259e, 0x08d8ec96, + 0x08e9b38d, 0x08fa7a85, 0x090b417d, 0x091c0874, + 0x092ccf6c, 0x093d9664, 0x094e5d5b, 0x095f2453, + 0x096feb4a, 0x0980b242, 0x0991793a, 0x09a24031, + 0x09b30729, 0x09c3ce21, 0x09d49518, 0x09e55c10, + 0x09f62307, 0x0a06e9ff, 0x0a17b0f7, 0x0a2877ee, + 0x0a393ee6, 0x0a4a05de, 0x0a5accd5, 0x0a6b93cd, + 0x0a7c5ac4, 0x0a8d21bc, 0x0a9de8b4, 0x0aaeafab, + 0x0abf76a3, 0x0ad03d9b, 0x0ae10492, 0x0af1cb8a, + 0x0b029281, 0x0b135979, 0x0b242071, 0x0b34e768, + 0x0b45ae60, 0x0b567558, 0x0b673c4f, 0x0b780347, + 0x0b88ca3e, 0x0b999136, 0x0baa582e, 0x0bbb1f25, + 0x0bcbe61d, 0x0bdcad15, 0x0bed740c, 0x0bfe3b04, + 0x0c0f01fc, 0x0c1fc8f3, 0x0c308feb, 0x0c4156e2, + 0x0c521dda, 0x0c62e4d2, 0x0c73abc9, 0x0c8472c1, + 0x0c9539b9, 0x0ca600b0, 0x0cb6c7a8, 0x0cc78e9f, + 0x0cd85597, 0x0ce91c8f, 0x0cf9e386, 0x0d0aaa7e, + 0x0d1b7176, 0x0d2c386d, 0x0d3cff65, 0x0d4dc65c, + 0x0d5e8d54, 0x0d6f544c, 0x0d801b43, 0x0d90e23b, + 0x0da1a933, 0x0db2702a, 0x0dc33722, 0x0dd3fe19, + 0x0de4c511, 0x0df58c09, 0x0e065300, 0x0e1719f8, + 0x0e27e0f0, 0x0e38a7e7, 0x0e496edf, 0x0e5a35d6, + 0x0e6afcce, 0x0e7bc3c6, 0x0e8c8abd, 0x0e9d51b5, + 0x0eae18ad, 0x0ebedfa4, 0x0ecfa69c, 0x0ee06d94, + 0x0ef1348b, 0x0f01fb83, 0x0f12c27a, 0x0f238972, + 0x0f34506a, 0x0f451761, 0x0f55de59, 0x0f66a551, + 0x0f776c48, 0x0f883340, 0x0f98fa37, 0x0fa9c12f, + 0x0fba8827, 0x0fcb4f1e, 0x0fdc1616, 0x0fecdd0e, + 0x0ffda405, 0x100e6afd, 0x101f31f4, 0x102ff8ec, + 0x1040bfe4, 0x105186db, 0x10624dd3, 0x107314cb, + 0x1083dbc2, 0x1094a2ba, 0x10a569b1, 0x10b630a9 }; -u_long ustotshi[16] = { - 0x00000000, 0x10c6f79a, 0x218def35, 0x3254e6cf, - 0x431bde6a, 0x53e2d604, 0x64a9cd9f, 0x7570c539, - 0x8637bcd3, 0x96feb46e, 0xa7c5ac08, 0xb88ca3a3, - 0xc9539b3d, 0xda1a92d7, 0xeae18a72, 0xfba8820c, +const u_int32 ustotshi[16] = { + 0x00000000, 0x10c6f7a1, 0x218def41, 0x3254e6e2, + 0x431bde83, 0x53e2d624, 0x64a9cdc4, 0x7570c565, + 0x8637bd06, 0x96feb4a6, 0xa7c5ac47, 0xb88ca3e8, + 0xc9539b89, 0xda1a9329, 0xeae18aca, 0xfba8826b }; diff --git a/libparse/parse.c b/libparse/parse.c index 83e560aff..a751bdfbb 100644 --- a/libparse/parse.c +++ b/libparse/parse.c @@ -128,10 +128,6 @@ parse_timedout( delta.tv_usec += 1000000; } #else - extern long tstouslo[]; - extern long tstousmid[]; - extern long tstoushi[]; - l_fp delt; delt = tstamp->fp;