lfpinit() signed or unsigned?

Gary E. Miller gem at rellim.com
Thu Mar 9 21:29:40 UTC 2017


Yo Eric!

> > > Would it help to have another signed type?    
> > 
> > The short answer is "no".  The longer answer:  
> 
> I'm starting to disagree, I see a need for only a signed type.
> 
> Too often the unsigned type is then used to compute offsets and the
> casts get ugly.

Gack...  I gotta do a quick U-turn on this.  I found some pretty hidden
assumptions that I did not expect in the code.  Assumptions that I will
document, in the code, for the next poor soul that looks at this.

I had assumed, and code does not document, that l_fp was sometimes
used as like a timespec (time_t seconds and nanoseconds UNIX epoch).
Since time_t is signed, it can also be used as an offset of seconds and
nanoseconds.  But is is also used to represent NTP time which uses 
a base apoch of 12/1/1 BC!

A signed l_fp is just fine for POSIX time, until overflow at 0x7fffffff,
which is decimal 2147483747 seconds, the dreaded "Mon Jan 18 19:15:47
PST 2038"

To convert POSIX time to NTP time you add 0x83aa7e80 (decimal 2208988800).
Note that number does not fit is a 32 bit type, signed or unsigned.

As I write this, the time now is POSIX: 1489094096.  As NTP time it
is 3698082896 (0x160ad3a8).  Notice that is 33 bits!

Sure ntpd is working now, but it is doing so using overflow arithmetic!

I only had to look at the clang output for a month to see this.

Please ponder that again: ntpd is using overflow arithmetic!  No wonder
the code is so touchy.

I see 12 uses of this in the code, so fixable, but I'll need to stare
at my navel a bit longer for enlightenment...

RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
	gem at rellim.com  Tel:+1 541 382 8588

	    Veritas liberabit vos. -- Quid est veritas?
    "If you can’t measure it, you can’t improve it." - Lord Kelvin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ntpsec.org/pipermail/devel/attachments/20170309/267dcf1d/attachment.bin>


More information about the devel mailing list