On Wed, 7 Aug 2013, Hiroki Sato wrote:
Ian Lepore <i...@freebsd.org> wrote
in <1375807689.3320.48.ca...@revolution.hippie.lan>:
ia> On Tue, 2013-08-06 at 15:49 +0000, Hiroki Sato wrote:
ia> > /* Generate maximum time in timespec. */
ia> > - memset(&tm_max.tv_sec, 0xff, sizeof(tm_max.tv_sec));
ia> > - memset(&tm_max.tv_nsec, 0xff, sizeof(tm_max.tv_nsec));
ia> > - tm_max.tv_sec &= ~(1UL << (sizeof(tm_max.tv_sec) * 8 - 1));
ia> > - tm_max.tv_nsec &= ~(1UL << (sizeof(tm_max.tv_nsec) * 8 - 1));
ia> > + tm_max.tv_sec = (-1) & ~((time_t)1 << ((sizeof(tm_max.tv_sec) * 8) -
1));
ia> > + tm_max.tv_nsec = (-1) & ~((long)1 << ((sizeof(tm_max.tv_nsec) * 8) -
1));
ia> >
ia> > /* set log level */
ia> > if (dflag > 1)
ia>
ia> The maximum number of nsec is 999999999 regardless of the type of
ia> tv_nsec.
ia>
ia> That expression for max time_t sure is ugly, but I can't think of
ia> anything that isn't just differently-ugly. At least the comment makes
ia> the purpose clear.
This was defined as {0x7fffffff, 0x7fffffff} in the original code and
used just as a large enough value to make a conditional (tm_max >
tm_other) be always true, not the exact maximum value. Yes, this is
ugly and can be improved.
After the change to monotonic times, the max time in seconds can't be
more than a few million. 1 non-leap year = 31.536 million seconds.
This is not quite enough for anyone, so use LONG_MAX > 2147 million
to work for 68 years. Thus all uses of intmax_t are bogus, and even
all uses of long are unnecessary, since they are only needed to support
systems with < 32-bit ints. but no such systems are supported.
The change to monotonic times gave lots of style bugs. Mainly expansion
of lines beyond 80 columns by large ugly code. In the above, the lines
with the complicated expressions for the maximums became too long.
Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"