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. -- Hiroki
pgpXSTFRUhTGW.pgp
Description: PGP signature