Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Nov 2003 07:04:04 -0600
From:      Jacques Vidrine <nectar@freebsd.org>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: __TIME_MIN/__TIME_MAX
Message-ID:  <3FB62444.9000102@freebsd.org>
In-Reply-To: <20031115190419.G1478@gamplex.bde.org>
References:  <20031114194119.GA94198@madman.celabo.org> <20031115114906.L11453@gamplex.bde.org> <3FB5B258.6010207@freebsd.org> <20031115190419.G1478@gamplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans said the following on 11/15/03 2:17 AM:
> On Fri, 14 Nov 2003, Jacques Vidrine wrote:
>>  So this kind of thing OK?
>>
>>   long n;
>>   time_t t;
>>   errno = 0;
>>   n = strtoul(...);
>>   if (errno == ERANGE || (long)(t = n) != n)
>>      /* out of range */;
> 
> 
> Not quite like that.  strtoul() returns an unsigned long whose value may
> be lost by assigning it to a plain long.  Mixtures of signed and unsigned
> types are tricky to handle as usual.  Suppose we make n unsigned long
> and it has value ULONG_MAX, and time_t is long, then (t = n) == n,
> but t doesn't actually represent n (casting (t = n) to long or unsigned
> long doesn't help).  So it seems to be necessary to be aware that time_t
> is signed and either use strtol() initially or check that t >= 0 if
> n is unsigned long.  If time_t is actually signed then we may get a GCC
> warning for this check...

Doh, sorry, that's a typo.  I meant strtol (which is what is currently
used in the relevant portion of libc--- strptime.c, BTW).  Negative
values must be allowed here.

Cheers,
-- 
Jacques Vidrine   NTT/Verio SME      FreeBSD UNIX       Heimdal
nectar@celabo.org jvidrine@verio.net nectar@freebsd.org nectar@kth.se



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