This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Y2031 problem in tst-fseek.c ...


Denis Vlasenko wrote:
On 25 July 2003 07:03, Dan Kegel wrote:

OK, not that this is pressing or anything, but
IIRC in the year 2031, time() will go negative,
and for the next bunch of years, the sequence
   t0 = time(0);
   sleep(1);
   t1 = time(0);
   assert(t1 > t0);
will fail.


-2 > -3

(sorry for the pedantic waste of bandwidth...) Sure, but if the sleep(1) occurs right at rollover, the test will fail spuriously. This is not a serious worry, but since the fix is so simple, it seems worth doing as a matter of course: just turn the >'s into subtractions: t0 = time(0); sleep(1); t1 = time(0); dt = t1 - t0; assert(dt > 0); Nothing fancy there, and yet it won't fail at wraparound. You can even make the test stronger, if you know the program isn't going to be swapped out for more than N seconds, by verifying that dt is less than or equal to N.

This is more important when dealing with timers that
roll over more frequently.
- Dan

--
Dan Kegel
http://www.kegel.com
http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=78045


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]