summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2002-09-03 04:34:10 +0000
committerpeter <peter@FreeBSD.org>2002-09-03 04:34:10 +0000
commit2dc22e49268ddebe68cded7233384ee625be3a6d (patch)
treed0ac221786ea37c1b0d16321e110d967a03fe09d /lib/libc
parent20072affec15c51574156e050f90e3cb9583209c (diff)
downloadFreeBSD-src-2dc22e49268ddebe68cded7233384ee625be3a6d.zip
FreeBSD-src-2dc22e49268ddebe68cded7233384ee625be3a6d.tar.gz
Fix a nasty bug exposed by mktime() when time_t is significantly bigger
than 32 bits. It was trying to figure out things like the day of week of when time_t is roughly 2^62 etc. Make a better guess for the starting point for the binary search that works on both 32 and 64 bit types. I have been using this for a while now.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdtime/localtime.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c
index 3531aa4..f37f332 100644
--- a/lib/libc/stdtime/localtime.c
+++ b/lib/libc/stdtime/localtime.c
@@ -1476,6 +1476,12 @@ int * const okayp;
*/
bits = TYPE_BIT(time_t) - 1;
/*
+ * Limit to 32 bits or the things go crazy
+ * when it tries to figure out times near 2^62 etc.
+ */
+ if (bits > 31)
+ bits = 31;
+ /*
** If time_t is signed, then 0 is just above the median,
** assuming two's complement arithmetic.
** If time_t is unsigned, then (1 << bits) is just above the median.
OpenPOWER on IntegriCloud