glibc/time
Paul Eggert 8e6fd2bdb2 Merge mktime, timegm from upstream Gnulib
[BZ #23603][BZ #16346]
This fixes some obscure problems with integer overflow.
Although it looks scary, it is almost all a byte-for-byte copy
from Gnulib, and the Gnulib code has been tested reasonably well.
* include/intprops.h: New file, copied from Gnulib.
* include/verify.h, time/mktime-internal.h:
New tiny files, simplified from Gnulib.
* time/mktime.c: Copy from Gnulib.  This has the following changes:
Do not include config.h if DEBUG_MKTIME is nonzero.
Include stdbool.h, intprops.h, verify.h.
Include string.h only if needed.
Include stdlib.h on MS-Windows.
Include mktime-internal.h.
(DEBUG_MKTIME): Default to 0, and simplify later uses.
(NEED_MKTIME_INTERNAL, NEED_MKTIME_WINDOWS)
(NEED_MKTIME_WORKING): Give default values to pacify -Wundef,
which glibc uses.  Default NEED_MKTIME_WORKING to DEBUG_MKTIME, to
simplify later conditionals; default the others to zero.  Use
these conditionals to express only the code needed on the current
platform.  In uses of these conditionals, explicitly spell out how
_LIBC affects things, so it’s easier to review from a glibc
viewpoint.
(WRAPV): Remove; no longer needed now that we have
systematic overflow checking.
(my_tzset, __tzset) [!_LIBC]: New function and macro, to better
compartmentalize tzset issues.  Move system-dependent tzsettish
code here from mktime.
(verify): Remove; now done by verify.h.  All uses changed.
(long_int): Use a more-conservative definition, to avoid
integer overflow.
(SHR): Remove, replacing with ...
(shr): New function, which means we needn’t worry about side
effects in args, and conversion analysis is simpler.
(TYPE_IS_INTEGER, TYPE_TWOS_COMPLEMENT, TYPE_SIGNED, TYPE_MINIMUM)
(TYPE_MAXIMUM, TIME_T_MIN, TIME_T_MAX, TIME_T_MIDPOINT)
(time_t_avg, time_t_add_ok): Remove.
(mktime_min, mktime_max): New constants.
(leapyear, isdst_differ): Use bool for booleans.
(ydhms_diff, guess_time_tm, ranged_convert, __mktime_internal):
Use long_int, not time_t, for mktime differences.
(long_int_avg): New function, replacing time_t_avg.
INT_ADD_WRAPV replaces time_t_add_ok.
(guess_time_tm): 6th arg is now long_int, not time_t const *.
All uses changed.
(convert_time): New function.
(ranged_convert): Use it.
(__mktime_internal): Last arg now points to mktime_offset_t, not
time_t.  All uses changed.  This is a no-op on glibc, where
mktime_offset_t is always time_t.  Use int, not time_t, for UTC
offset guess.  Directly check for integer overflow instead of
using a heuristic that works only 99.9...% of the time.
Access *OFFSET only once, to avoid an unlikely race if the
compiler delays a load and if this cascades into a signed integer
overflow.
(mktime): Move tzsettish code to my_tzset, and move
localtime_offset to within mktime so that it doesn’t
need a separate ifdef.
(main) [DEBUG_MKTIME]: Speed up by using localtime_r
instead of localtime.
* time/timegm.c: Copy from Gnulib.  This has the following changes:
Include mktime-internal.h.
[!_LIBC]: Include config.h and time.h.  Do not include
timegm.h or time_r.h.  Make __mktime_internal a macro,
and include mktime-internal.h to get its declaration.
(timegm): Temporary is now mktime_offset_t, not time_t.
This affects only Gnulib.
2018-09-19 17:09:08 -07:00
..
bits/types Use _STRUCT_TIMESPEC as guard in <bits/types/struct_timespec.h> [BZ #23349] 2018-06-28 13:12:16 +02:00
sys Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
adjtime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
alt_digit.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
asctime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
bug-asctime_r.c [BZ #1468] 2005-10-14 17:20:58 +00:00
bug-asctime.c [BZ #1460] 2005-10-14 15:17:40 +00:00
bug-getdate1.c support: Introduce new subdirectory for test infrastructure 2016-12-09 08:18:27 +01:00
bug-mktime1.c [BZ #2821] 2006-09-09 16:56:29 +00:00
clock.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
clocktest.c Add missing header files throughout the testsuite. 2017-02-16 17:33:18 -05:00
ctime_r.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ctime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
datemsk * time/Makefile (tst-getdate-ENV): Add TZDIR to environment. 2001-07-18 09:43:36 +00:00
Depend * time/Makefile (tst-getdate-ENV): Add TZDIR to environment. 2001-07-18 09:43:36 +00:00
difftime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
dysize.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
era.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
ftime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
getdate.c Fix -Os ferror_unlocked linknamespace, localplt issues (bug 15105, bug 19463). 2018-02-19 17:32:34 +00:00
getitimer.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
gettimeofday.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
gmtime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
lc-time-cleanup.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
localtime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
Makefile Fix year 2039 bug for localtime with 64-bit time_t (bug 22639). 2018-05-18 11:57:15 +00:00
mktime-internal.h Merge mktime, timegm from upstream Gnulib 2018-09-19 17:09:08 -07:00
mktime.c Merge mktime, timegm from upstream Gnulib 2018-09-19 17:09:08 -07:00
offtime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
setitimer.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
settimeofday.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
stime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
strftime_l.c Abbreviated alternative month names (%Ob) also added (bug 10871). 2018-01-22 11:26:55 +01:00
strftime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
strptime_l.c Abbreviated alternative month names (%Ob) also added (bug 10871). 2018-01-22 11:26:55 +01:00
strptime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
test_time.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
time.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
time.h time: Reference CLOCKS_PER_SEC in clock comment [BZ #22735] 2018-02-02 11:59:31 +01:00
timegm.c Merge mktime, timegm from upstream Gnulib 2018-09-19 17:09:08 -07:00
timespec_get.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst_wcsftime.c Update. 1999-06-16 22:55:47 +00:00
tst-ftime_l.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-ftime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-getdate.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-mktime2.c Use TIME_T_MAX and TIME_T_MIN in tst-mktime2.c 2016-01-14 16:35:40 -08:00
tst-mktime3.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-mktime.c Modify several tests to use test-skeleton.c 2014-11-05 15:24:08 +05:30
tst-posixtz.c Add missing header files throughout the testsuite. 2017-02-16 17:33:18 -05:00
tst-strftime.c Fix BZ #18985 -- out of range data to strftime() causes a segfault 2015-09-26 13:27:48 -07:00
tst-strptime2.c Split DIAG_* macros to new header libc-diag.h. 2017-02-25 09:59:46 -05:00
tst-strptime3.c time: ensure failing strptime() tests are reported correctly 2015-03-06 06:06:26 -05:00
tst-strptime-whitespace.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-strptime.c ru_RU, ru_UA: Add alternative month names (bug 10871). 2018-01-29 13:14:45 +01:00
tst-tzname.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
tst-y2039.c Fix year 2039 bug for localtime with 64-bit time_t (bug 22639). 2018-05-18 11:57:15 +00:00
tzfile.c Simplify tzfile fstat failure code 2018-09-18 15:09:01 -07:00
tzset.c Fix year 2039 bug for localtime with 64-bit time_t (bug 22639). 2018-05-18 11:57:15 +00:00
Versions Sort Versions files 2013-02-17 16:34:04 +01:00
wcsftime_l.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00
wcsftime.c Update copyright dates with scripts/update-copyrights. 2018-01-01 00:32:25 +00:00