Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Aug 2013 14:17:35 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Hiroki Sato <hrs@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, ian@FreeBSD.org
Subject:   Re: svn commit: r253995 - in head/usr.sbin: rtadvd rtsold
Message-ID:  <20130807135707.D1390@besplex.bde.org>
In-Reply-To: <20130807.023507.62577067127422432.hrs@allbsd.org>
References:  <201308061549.r76FnImt054058@svn.freebsd.org> <1375807689.3320.48.camel@revolution.hippie.lan> <20130807.023507.62577067127422432.hrs@allbsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 7 Aug 2013, Hiroki Sato wrote:

> Ian Lepore <ian@FreeBSD.org> wrote
>  in <1375807689.3320.48.camel@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130807135707.D1390>