diff options
Diffstat (limited to 'lib/nstrftime.c')
-rw-r--r-- | lib/nstrftime.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/nstrftime.c b/lib/nstrftime.c index 2816cf4d58b..7d5a97f7635 100644 --- a/lib/nstrftime.c +++ b/lib/nstrftime.c @@ -21,7 +21,6 @@ # define HAVE_TM_GMTOFF 1 # define HAVE_TM_ZONE 1 # define HAVE_TZNAME 1 -# define HAVE_TZSET 1 # include "../locale/localeinfo.h" #else # include <config.h> @@ -34,6 +33,7 @@ #endif #include <ctype.h> +#include <errno.h> #include <time.h> #if HAVE_TZNAME && !HAVE_DECL_TZNAME @@ -163,7 +163,10 @@ extern char *tzname[]; size_t _w = pad == L_('-') || width < 0 ? 0 : width; \ size_t _incr = _n < _w ? _w : _n; \ if (_incr >= maxsize - i) \ - return 0; \ + { \ + errno = ERANGE; \ + return 0; \ + } \ if (p) \ { \ if (_n < _w) \ @@ -365,7 +368,7 @@ tm_diff (const struct tm *a, const struct tm *b) #define ISO_WEEK1_WDAY 4 /* Thursday */ #define YDAY_MINIMUM (-366) static int iso_week_days (int, int); -#ifdef __GNUC__ +#if defined __GNUC__ || defined __clang__ __inline__ #endif static int @@ -389,7 +392,6 @@ iso_week_days (int yday, int wday) #endif #ifdef my_strftime -# undef HAVE_TZSET # define extra_args , tz, ns # define extra_args_spec , timezone_t tz, int ns #else @@ -449,6 +451,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) size_t maxsize = (size_t) -1; #endif + int saved_errno = errno; int hour12 = tp->tm_hour; #ifdef _NL_CURRENT /* We cannot make the following values variables since we must delay @@ -523,7 +526,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) { /* POSIX.1 requires that local time zone information be used as though strftime called tzset. */ -# if HAVE_TZSET +# ifndef my_strftime if (!*tzset_called) { tzset (); @@ -1188,7 +1191,13 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) time_t t; ltm = *tp; + ltm.tm_yday = -1; t = mktime_z (tz, <m); + if (ltm.tm_yday < 0) + { + errno = EOVERFLOW; + return 0; + } /* Generate string value for T using time_t arithmetic; this works even if sizeof (long) < sizeof (time_t). */ @@ -1417,7 +1426,7 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) /* POSIX.1 requires that local time zone information be used as though strftime called tzset. */ -# if HAVE_TZSET +# ifndef my_strftime if (!*tzset_called) { tzset (); @@ -1486,5 +1495,6 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize) *p = L_('\0'); #endif + errno = saved_errno; return i; } |