Subject: Re: bug#7928: mktime test in configure: UB resulting in infinite loop

From: Rich Felker <[email-masked]>
Date: Fri, 28 Jan 2011 14:13:59 -0500

On Fri, Jan 28, 2011 at 06:57:22PM +0100, Bruno Haible wrote:
> Rich Felker wrote:
> > Testing which of the three allowable signed integer
> > representations is used is easy: compare ~(t)1 against and -(t)1 and
> > -(t)2.
> 
> Testing which of the three signed integer representations is in use
> is not even needed: Your formula
>   ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)
> yields the correct result in all three cases.

It yields the correct max. However, getting the min requires knowing
whether min is -max or -max-1. This depends on which of the
representations is used:

min = ~(t)1 == -(t)2 ? -max-1 : -max;

Rich