summaryrefslogtreecommitdiff
path: root/lib/mktime.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-05-01 11:44:51 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-05-01 17:27:02 -0700
commitb28c2cda0e90ccad85a99c48dded5624e39d28ac (patch)
treeefcd4824fbd894bb15b10c43bd20e2258ebc3870 /lib/mktime.c
parent6ed53f13bc39d9a0252549e98a2a59441fb2351f (diff)
downloadgnulib-b28c2cda0e90ccad85a99c48dded5624e39d28ac.tar.gz
Port mktime_internal offset to unsigned time_t
This avoids some assumptions about wraparound arithmetic on signed integer overflow. * lib/mktime-internal.h (mktime_offset_t): New type. (mktime_internal): Use it in decl. * lib/mktime.c, lib/timegm.c (mktime_offset_t) [_LIBC]: New type. * lib/mktime.c (__mktime_internal, localtime_offset): * lib/timegm.c (timegm): Use it. * m4/mktime.m4 (gl_TIME_T_IS_SIGNED): New macro. (gl_FUNC_MKTIME): Require it.
Diffstat (limited to 'lib/mktime.c')
-rw-r--r--lib/mktime.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/mktime.c b/lib/mktime.c
index 627b1a38d3..4f4f0bf34c 100644
--- a/lib/mktime.c
+++ b/lib/mktime.c
@@ -120,7 +120,9 @@ const unsigned short int __mon_yday[2][13] =
};
-#ifndef _LIBC
+#ifdef _LIBC
+typedef time_t mktime_offset_t;
+#else
/* Portable standalone applications should supply a <time.h> that
declares a POSIX-compliant localtime_r, for the benefit of older
implementations that lack localtime_r or have a nonstandard one.
@@ -296,7 +298,7 @@ ranged_convert (struct tm *(*convert) (const time_t *, struct tm *),
time_t
__mktime_internal (struct tm *tp,
struct tm *(*convert) (const time_t *, struct tm *),
- time_t *offset)
+ mktime_offset_t *offset)
{
time_t t, gt, t0, t1, t2;
struct tm tm;
@@ -518,11 +520,7 @@ __mktime_internal (struct tm *tp,
}
-/* FIXME: This should use a signed type wide enough to hold any UTC
- offset in seconds. 'int' should be good enough for GNU code. We
- can't fix this unilaterally though, as other modules invoke
- __mktime_internal. */
-static time_t localtime_offset;
+static mktime_offset_t localtime_offset;
/* Convert *TP to a time_t value. */
time_t