Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Aug 2017 20:59:23 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
Cc:        freebsd-bugs@freebsd.org
Subject:   Re: [Bug 221418] FreeBSD 10.4-PRERELEASE fails to build on systems using 32 bit time_t since r322315.
Message-ID:  <20170812204159.O1958@besplex.bde.org>
In-Reply-To: <bug-221418-8-8Qobma2zSB@https.bugs.freebsd.org/bugzilla/>
References:  <bug-221418-8@https.bugs.freebsd.org/bugzilla/> <bug-221418-8-8Qobma2zSB@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 11 Aug 2017 a bug that doesn't want replies@freebsd.org wrote:

> --- Comment #1 from Conrad Meyer <cem@freebsd.org> ---
> Truncated INT64_MIN should be INT32_MIN on 2's complement, not 0.  Seems like
> we just lack a (time_t) cast on the value.

Truncated INT64_MIN should be and is, 0 in 2's complement, since all of
its low 32 bits are 0.  In 1's complement, it should be -0, since all
of its low 32 bits are 1.

Casting to time_t is no different to assigning to time_t, except compilers
usually only warn about overflow for the assignent.  Casting thus enlarges
the bug by breaking the warning about overflow.

Related to this, the special value for possibly-invalid time_t's is
((time_t)-1), not some large negative value.  This is large and positive
if time_t is unsigned.  In POSIX, times before the Epoch are invalid, but
(time_t)-1) might be valid if it is positive.  In Standard C, (time_t)-1)
might be valid even if it is -1.

I think the code needs a large negative value for technical reasons.
INT64_MIN is very bogus for this, since 69 years in the past given by
INT32_MIN should be enough for anyone, and further in the past than
that is unrepresentable by time_t on systems with 32-bit signed time_t.
If time_t is unsigned, no negative values are representable, so casts
to int but not to time_t might be needed.

> With regards to your patch, CHAR_BIT is always 8 on FreeBSD.

CHAR_BIT is 8 on all POSIX systems later than 2001.

CHAR_BIT is often spelled NBBY in BSD.  NBBY is less verbose than CHAR_BIT
and less cryptic than 8.

Bruce



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