Brad Bishop | 34ae600 | 2019-04-08 15:21:03 -0400 | [diff] [blame^] | 1 | From d672de675a16e5ab9efcf783705cbd171f38188e Mon Sep 17 00:00:00 2001 |
| 2 | From: "Billy O'Neal (VC LIBS)" <bion@microsoft.com> |
| 3 | Date: Thu, 28 Mar 2019 15:17:12 -0700 |
| 4 | Subject: [PATCH] Avoid tripping over 32 bit time_t mistakes. |
| 5 | |
| 6 | Resolves https://github.com/Microsoft/cpprestsdk/issues/1090 |
| 7 | --- |
| 8 | Release/src/utilities/asyncrt_utils.cpp | 30 ++--- |
| 9 | Release/tests/functional/utils/datetime.cpp | 140 ++++++++++---------- |
| 10 | 2 files changed, 84 insertions(+), 86 deletions(-) |
| 11 | |
| 12 | diff --git a/Release/src/utilities/asyncrt_utils.cpp b/Release/src/utilities/asyncrt_utils.cpp |
| 13 | index 4a692e5fa..986b64bb7 100644 |
| 14 | --- a/Release/src/utilities/asyncrt_utils.cpp |
| 15 | +++ b/Release/src/utilities/asyncrt_utils.cpp |
| 16 | @@ -618,7 +618,7 @@ std::string __cdecl conversions::to_utf8string(const utf16string& value) { retur |
| 17 | |
| 18 | utf16string __cdecl conversions::to_utf16string(const std::string& value) { return utf8_to_utf16(value); } |
| 19 | |
| 20 | -static const uint64_t ntToUnixOffsetSeconds = 11644473600U; // diff between windows and unix epochs (seconds) |
| 21 | +static const int64_t ntToUnixOffsetSeconds = 11644473600; // diff between windows and unix epochs (seconds) |
| 22 | |
| 23 | datetime __cdecl datetime::utc_now() |
| 24 | { |
| 25 | @@ -634,10 +634,10 @@ datetime __cdecl datetime::utc_now() |
| 26 | #else // LINUX |
| 27 | struct timeval time; |
| 28 | gettimeofday(&time, nullptr); |
| 29 | - uint64_t result = ntToUnixOffsetSeconds + time.tv_sec; |
| 30 | + int64_t result = ntToUnixOffsetSeconds + time.tv_sec; |
| 31 | result *= _secondTicks; // convert to 10e-7 |
| 32 | result += time.tv_usec * 10; // convert and add microseconds, 10e-6 to 10e-7 |
| 33 | - return datetime(result); |
| 34 | + return datetime(static_cast<interval_type>(result)); |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | @@ -646,7 +646,7 @@ static const char monthNames[] = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0Jul\0Aug\0Sep\0O |
| 39 | |
| 40 | utility::string_t datetime::to_string(date_format format) const |
| 41 | { |
| 42 | - const uint64_t input = m_interval / _secondTicks; // convert to seconds |
| 43 | + const int64_t input = static_cast<int64_t>(m_interval / _secondTicks); // convert to seconds |
| 44 | const int frac_sec = static_cast<int>(m_interval % _secondTicks); |
| 45 | const time_t time = static_cast<time_t>(input - ntToUnixOffsetSeconds); |
| 46 | struct tm t; |
| 47 | @@ -797,22 +797,20 @@ static int atoi2(const CharT* str) |
| 48 | return (static_cast<unsigned char>(str[0]) - '0') * 10 + (static_cast<unsigned char>(str[1]) - '0'); |
| 49 | } |
| 50 | |
| 51 | -static const time_t maxTimeT = sizeof(time_t) == 4 ? (time_t)INT_MAX : (time_t)LLONG_MAX; |
| 52 | - |
| 53 | -static time_t timezone_adjust(time_t result, unsigned char chSign, int adjustHours, int adjustMinutes) |
| 54 | +static int64_t timezone_adjust(int64_t result, unsigned char chSign, int adjustHours, int adjustMinutes) |
| 55 | { |
| 56 | if (adjustHours > 23) |
| 57 | { |
| 58 | - return (time_t)-1; |
| 59 | + return -1; |
| 60 | } |
| 61 | |
| 62 | // adjustMinutes > 59 is impossible due to digit 5 check |
| 63 | const int tzAdjust = adjustMinutes * 60 + adjustHours * 60 * 60; |
| 64 | if (chSign == '-') |
| 65 | { |
| 66 | - if (maxTimeT - result < tzAdjust) |
| 67 | + if (INT64_MAX - result < tzAdjust) |
| 68 | { |
| 69 | - return (time_t)-1; |
| 70 | + return -1; |
| 71 | } |
| 72 | |
| 73 | result += tzAdjust; |
| 74 | @@ -821,7 +819,7 @@ static time_t timezone_adjust(time_t result, unsigned char chSign, int adjustHou |
| 75 | { |
| 76 | if (tzAdjust > result) |
| 77 | { |
| 78 | - return (time_t)-1; |
| 79 | + return -1; |
| 80 | } |
| 81 | |
| 82 | result -= tzAdjust; |
| 83 | @@ -830,10 +828,10 @@ static time_t timezone_adjust(time_t result, unsigned char chSign, int adjustHou |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | -static time_t make_gm_time(struct tm* t) |
| 88 | +static int64_t make_gm_time(struct tm* t) |
| 89 | { |
| 90 | #ifdef _MSC_VER |
| 91 | - return _mkgmtime(t); |
| 92 | + return static_cast<int64_t>(_mkgmtime(t)); |
| 93 | #elif (defined(ANDROID) || defined(__ANDROID__)) |
| 94 | // HACK: The (nonportable?) POSIX function timegm is not available in |
| 95 | // bionic. As a workaround[1][2], we set the C library timezone to |
| 96 | @@ -867,9 +865,9 @@ static time_t make_gm_time(struct tm* t) |
| 97 | unsetenv("TZ"); |
| 98 | } |
| 99 | } |
| 100 | - return time; |
| 101 | + return static_cast<int64_t>(time); |
| 102 | #else // ^^^ ANDROID // Other POSIX platforms vvv |
| 103 | - return timegm(t); |
| 104 | + return static_cast<int64_t>(timegm(t)); |
| 105 | #endif // _MSC_VER |
| 106 | } |
| 107 | |
| 108 | @@ -916,7 +914,7 @@ zone = "UT" / "GMT" ; Universal Time |
| 109 | datetime __cdecl datetime::from_string(const utility::string_t& dateString, date_format format) |
| 110 | { |
| 111 | datetime result; |
| 112 | - time_t seconds; |
| 113 | + int64_t seconds; |
| 114 | uint64_t frac_sec = 0; |
| 115 | struct tm t{}; |
| 116 | auto str = dateString.c_str(); |
| 117 | diff --git a/Release/tests/functional/utils/datetime.cpp b/Release/tests/functional/utils/datetime.cpp |
| 118 | index ae7f7a5e4..acd6fddb0 100644 |
| 119 | --- a/Release/tests/functional/utils/datetime.cpp |
| 120 | +++ b/Release/tests/functional/utils/datetime.cpp |
| 121 | @@ -133,75 +133,77 @@ SUITE(datetime) |
| 122 | |
| 123 | TEST(parsing_time_rfc1123_accepts_each_day) |
| 124 | { |
| 125 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:00 GMT"), (time_t) 0); |
| 126 | - TestRfc1123IsTimeT(_XPLATSTR("Fri, 02 Jan 1970 00:00:00 GMT"), (time_t) 86400 * 1); |
| 127 | - TestRfc1123IsTimeT(_XPLATSTR("Sat, 03 Jan 1970 00:00:00 GMT"), (time_t) 86400 * 2); |
| 128 | - TestRfc1123IsTimeT(_XPLATSTR("Sun, 04 Jan 1970 00:00:00 GMT"), (time_t) 86400 * 3); |
| 129 | - TestRfc1123IsTimeT(_XPLATSTR("Mon, 05 Jan 1970 00:00:00 GMT"), (time_t) 86400 * 4); |
| 130 | - TestRfc1123IsTimeT(_XPLATSTR("Tue, 06 Jan 1970 00:00:00 GMT"), (time_t) 86400 * 5); |
| 131 | - TestRfc1123IsTimeT(_XPLATSTR("Wed, 07 Jan 1970 00:00:00 GMT"), (time_t) 86400 * 6); |
| 132 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:00 GMT"), (time_t)0); |
| 133 | + TestRfc1123IsTimeT(_XPLATSTR("Fri, 02 Jan 1970 00:00:00 GMT"), (time_t)86400 * 1); |
| 134 | + TestRfc1123IsTimeT(_XPLATSTR("Sat, 03 Jan 1970 00:00:00 GMT"), (time_t)86400 * 2); |
| 135 | + TestRfc1123IsTimeT(_XPLATSTR("Sun, 04 Jan 1970 00:00:00 GMT"), (time_t)86400 * 3); |
| 136 | + TestRfc1123IsTimeT(_XPLATSTR("Mon, 05 Jan 1970 00:00:00 GMT"), (time_t)86400 * 4); |
| 137 | + TestRfc1123IsTimeT(_XPLATSTR("Tue, 06 Jan 1970 00:00:00 GMT"), (time_t)86400 * 5); |
| 138 | + TestRfc1123IsTimeT(_XPLATSTR("Wed, 07 Jan 1970 00:00:00 GMT"), (time_t)86400 * 6); |
| 139 | } |
| 140 | |
| 141 | TEST(parsing_time_rfc1123_boundary_cases) |
| 142 | { |
| 143 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:00 GMT"), (time_t) 0); |
| 144 | - TestRfc1123IsTimeT(_XPLATSTR("19 Jan 2038 03:14:06 GMT"), (time_t) INT_MAX - 1); |
| 145 | -#ifndef _USE_32BIT_TIME_T |
| 146 | - TestRfc1123IsTimeT(_XPLATSTR("19 Jan 2038 03:13:07 -0001"), (time_t) INT_MAX); |
| 147 | - TestRfc1123IsTimeT(_XPLATSTR("19 Jan 2038 03:14:07 -0000"), (time_t) INT_MAX); |
| 148 | -#endif // _USE_32BIT_TIME_T |
| 149 | - TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 +0000"), (time_t) 1547507781); |
| 150 | - TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 -0001"), (time_t) 1547507841); |
| 151 | - TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 +0001"), (time_t) 1547507721); |
| 152 | - TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 -0100"), (time_t) 1547511381); |
| 153 | - TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 +0100"), (time_t) 1547504181); |
| 154 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:00 GMT"), (time_t)0); |
| 155 | + TestRfc1123IsTimeT(_XPLATSTR("19 Jan 2038 03:14:06 GMT"), (time_t)INT_MAX - 1); |
| 156 | + if (sizeof(time_t) == 8) |
| 157 | + { |
| 158 | + TestRfc1123IsTimeT(_XPLATSTR("19 Jan 2038 03:13:07 -0001"), (time_t)INT_MAX); |
| 159 | + TestRfc1123IsTimeT(_XPLATSTR("19 Jan 2038 03:14:07 -0000"), (time_t)INT_MAX); |
| 160 | + } |
| 161 | + TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 +0000"), (time_t)1547507781); |
| 162 | + TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 -0001"), (time_t)1547507841); |
| 163 | + TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 +0001"), (time_t)1547507721); |
| 164 | + TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 -0100"), (time_t)1547511381); |
| 165 | + TestRfc1123IsTimeT(_XPLATSTR("14 Jan 2019 23:16:21 +0100"), (time_t)1547504181); |
| 166 | } |
| 167 | |
| 168 | TEST(parsing_time_rfc1123_uses_each_field) |
| 169 | { |
| 170 | - TestRfc1123IsTimeT(_XPLATSTR("02 Jan 1970 00:00:00 GMT"), (time_t) 86400); |
| 171 | - TestRfc1123IsTimeT(_XPLATSTR("12 Jan 1970 00:00:00 GMT"), (time_t) 950400); |
| 172 | - TestRfc1123IsTimeT(_XPLATSTR("01 Feb 1970 00:00:00 GMT"), (time_t) 2678400); |
| 173 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 2000 00:00:00 GMT"), (time_t) 946684800); |
| 174 | -#ifndef _USE_32BIT_TIME_T |
| 175 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 2100 00:00:00 GMT"), (time_t) 4102444800); |
| 176 | -#endif // _USE_32BIT_TIME_T |
| 177 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1990 00:00:00 GMT"), (time_t) 631152000); |
| 178 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1971 00:00:00 GMT"), (time_t) 31536000); |
| 179 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 10:00:00 GMT"), (time_t) 36000); |
| 180 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 01:00:00 GMT"), (time_t) 3600); |
| 181 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:10:00 GMT"), (time_t) 600); |
| 182 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:01:00 GMT"), (time_t) 60); |
| 183 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:10 GMT"), (time_t) 10); |
| 184 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:01 GMT"), (time_t) 1); |
| 185 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 10:00:00 GMT"), (time_t) 36000); |
| 186 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 02:00:00 PST"), (time_t) 36000); |
| 187 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 03:00:00 PDT"), (time_t) 36000); |
| 188 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 03:00:00 MST"), (time_t) 36000); |
| 189 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 04:00:00 MDT"), (time_t) 36000); |
| 190 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 04:00:00 CST"), (time_t) 36000); |
| 191 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 05:00:00 CDT"), (time_t) 36000); |
| 192 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 05:00:00 EST"), (time_t) 36000); |
| 193 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 06:00:00 EDT"), (time_t) 36000); |
| 194 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 06:00:00 -0400"), (time_t) 36000); |
| 195 | - TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 05:59:00 -0401"), (time_t) 36000); |
| 196 | + TestRfc1123IsTimeT(_XPLATSTR("02 Jan 1970 00:00:00 GMT"), (time_t)86400); |
| 197 | + TestRfc1123IsTimeT(_XPLATSTR("12 Jan 1970 00:00:00 GMT"), (time_t)950400); |
| 198 | + TestRfc1123IsTimeT(_XPLATSTR("01 Feb 1970 00:00:00 GMT"), (time_t)2678400); |
| 199 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 2000 00:00:00 GMT"), (time_t)946684800); |
| 200 | + if (sizeof(time_t) == 8) |
| 201 | + { |
| 202 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 2100 00:00:00 GMT"), (time_t)4102444800); |
| 203 | + } |
| 204 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1990 00:00:00 GMT"), (time_t)631152000); |
| 205 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1971 00:00:00 GMT"), (time_t)31536000); |
| 206 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 10:00:00 GMT"), (time_t)36000); |
| 207 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 01:00:00 GMT"), (time_t)3600); |
| 208 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:10:00 GMT"), (time_t)600); |
| 209 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:01:00 GMT"), (time_t)60); |
| 210 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:10 GMT"), (time_t)10); |
| 211 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 00:00:01 GMT"), (time_t)1); |
| 212 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 10:00:00 GMT"), (time_t)36000); |
| 213 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 02:00:00 PST"), (time_t)36000); |
| 214 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 03:00:00 PDT"), (time_t)36000); |
| 215 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 03:00:00 MST"), (time_t)36000); |
| 216 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 04:00:00 MDT"), (time_t)36000); |
| 217 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 04:00:00 CST"), (time_t)36000); |
| 218 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 05:00:00 CDT"), (time_t)36000); |
| 219 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 05:00:00 EST"), (time_t)36000); |
| 220 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 06:00:00 EDT"), (time_t)36000); |
| 221 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 06:00:00 -0400"), (time_t)36000); |
| 222 | + TestRfc1123IsTimeT(_XPLATSTR("01 Jan 1970 05:59:00 -0401"), (time_t)36000); |
| 223 | } |
| 224 | |
| 225 | TEST(parsing_time_rfc1123_max_days) |
| 226 | { |
| 227 | - TestRfc1123IsTimeT(_XPLATSTR("31 Jan 1970 00:00:00 GMT"), (time_t) 2592000); |
| 228 | - TestRfc1123IsTimeT(_XPLATSTR("28 Feb 2019 00:00:00 GMT"), (time_t) 1551312000); // non leap year allows feb 28 |
| 229 | - TestRfc1123IsTimeT(_XPLATSTR("29 Feb 2020 00:00:00 GMT"), (time_t) 1582934400); // leap year allows feb 29 |
| 230 | - TestRfc1123IsTimeT(_XPLATSTR("31 Mar 1970 00:00:00 GMT"), (time_t) 7689600); |
| 231 | - TestRfc1123IsTimeT(_XPLATSTR("30 Apr 1970 00:00:00 GMT"), (time_t) 10281600); |
| 232 | - TestRfc1123IsTimeT(_XPLATSTR("31 May 1970 00:00:00 GMT"), (time_t) 12960000); |
| 233 | - TestRfc1123IsTimeT(_XPLATSTR("30 Jun 1970 00:00:00 GMT"), (time_t) 15552000); |
| 234 | - TestRfc1123IsTimeT(_XPLATSTR("31 Jul 1970 00:00:00 GMT"), (time_t) 18230400); |
| 235 | - TestRfc1123IsTimeT(_XPLATSTR("31 Aug 1970 00:00:00 GMT"), (time_t) 20908800); |
| 236 | - TestRfc1123IsTimeT(_XPLATSTR("30 Sep 1970 00:00:00 GMT"), (time_t) 23500800); |
| 237 | - TestRfc1123IsTimeT(_XPLATSTR("31 Oct 1970 00:00:00 GMT"), (time_t) 26179200); |
| 238 | - TestRfc1123IsTimeT(_XPLATSTR("30 Nov 1970 00:00:00 GMT"), (time_t) 28771200); |
| 239 | - TestRfc1123IsTimeT(_XPLATSTR("31 Dec 1970 00:00:00 GMT"), (time_t) 31449600); |
| 240 | + TestRfc1123IsTimeT(_XPLATSTR("31 Jan 1970 00:00:00 GMT"), (time_t)2592000); |
| 241 | + TestRfc1123IsTimeT(_XPLATSTR("28 Feb 2019 00:00:00 GMT"), (time_t)1551312000); // non leap year allows feb 28 |
| 242 | + TestRfc1123IsTimeT(_XPLATSTR("29 Feb 2020 00:00:00 GMT"), (time_t)1582934400); // leap year allows feb 29 |
| 243 | + TestRfc1123IsTimeT(_XPLATSTR("31 Mar 1970 00:00:00 GMT"), (time_t)7689600); |
| 244 | + TestRfc1123IsTimeT(_XPLATSTR("30 Apr 1970 00:00:00 GMT"), (time_t)10281600); |
| 245 | + TestRfc1123IsTimeT(_XPLATSTR("31 May 1970 00:00:00 GMT"), (time_t)12960000); |
| 246 | + TestRfc1123IsTimeT(_XPLATSTR("30 Jun 1970 00:00:00 GMT"), (time_t)15552000); |
| 247 | + TestRfc1123IsTimeT(_XPLATSTR("31 Jul 1970 00:00:00 GMT"), (time_t)18230400); |
| 248 | + TestRfc1123IsTimeT(_XPLATSTR("31 Aug 1970 00:00:00 GMT"), (time_t)20908800); |
| 249 | + TestRfc1123IsTimeT(_XPLATSTR("30 Sep 1970 00:00:00 GMT"), (time_t)23500800); |
| 250 | + TestRfc1123IsTimeT(_XPLATSTR("31 Oct 1970 00:00:00 GMT"), (time_t)26179200); |
| 251 | + TestRfc1123IsTimeT(_XPLATSTR("30 Nov 1970 00:00:00 GMT"), (time_t)28771200); |
| 252 | + TestRfc1123IsTimeT(_XPLATSTR("31 Dec 1970 00:00:00 GMT"), (time_t)31449600); |
| 253 | } |
| 254 | |
| 255 | TEST(parsing_time_rfc1123_invalid_cases) |
| 256 | @@ -266,7 +268,7 @@ SUITE(datetime) |
| 257 | _XPLATSTR("Thu, 01 Jan 1970 00:00:00 G"), |
| 258 | _XPLATSTR("Thu, 01 Jan 1970 00:00:00 GM"), |
| 259 | _XPLATSTR("Fri, 01 Jan 1970 00:00:00 GMT"), // wrong day |
| 260 | - _XPLATSTR("01 Jan 4970 00:00:00 GMT"), // year too big |
| 261 | + _XPLATSTR("01 Jan 4970 00:00:00 GMT"), // year too big |
| 262 | _XPLATSTR("01 Jan 3001 00:00:00 GMT"), |
| 263 | _XPLATSTR("01 Xxx 1971 00:00:00 GMT"), // month bad |
| 264 | _XPLATSTR("00 Jan 1971 00:00:00 GMT"), // day too small |
| 265 | @@ -288,8 +290,8 @@ SUITE(datetime) |
| 266 | _XPLATSTR("01 Jan 1971 00:60:00 GMT"), // minute too big |
| 267 | _XPLATSTR("01 Jan 1971 00:00:70 GMT"), // second too big |
| 268 | _XPLATSTR("01 Jan 1971 00:00:61 GMT"), |
| 269 | - _XPLATSTR("01 Jan 1969 00:00:00 GMT"), // underflow |
| 270 | - _XPLATSTR("01 Jan 1969 00:00:00 CEST"), // bad tz |
| 271 | + _XPLATSTR("01 Jan 1969 00:00:00 GMT"), // underflow |
| 272 | + _XPLATSTR("01 Jan 1969 00:00:00 CEST"), // bad tz |
| 273 | _XPLATSTR("01 Jan 1970 00:00:00 +2400"), // bad tzoffsets |
| 274 | _XPLATSTR("01 Jan 1970 00:00:00 -3000"), |
| 275 | _XPLATSTR("01 Jan 1970 00:00:00 +2160"), |
| 276 | @@ -309,11 +311,12 @@ SUITE(datetime) |
| 277 | // boundary cases: |
| 278 | TestDateTimeRoundtrip(_XPLATSTR("1970-01-01T00:00:00Z")); // epoch |
| 279 | TestDateTimeRoundtrip(_XPLATSTR("2038-01-19T03:14:06+00:00"), _XPLATSTR("2038-01-19T03:14:06Z")); // INT_MAX - 1 |
| 280 | -#ifndef _USE_32BIT_TIME_T |
| 281 | - TestDateTimeRoundtrip(_XPLATSTR("2038-01-19T03:13:07-00:01"), |
| 282 | - _XPLATSTR("2038-01-19T03:14:07Z")); // INT_MAX after subtacting 1 |
| 283 | - TestDateTimeRoundtrip(_XPLATSTR("2038-01-19T03:14:07-00:00"), _XPLATSTR("2038-01-19T03:14:07Z")); |
| 284 | -#endif // _USE_32BIT_TIME_T |
| 285 | + if (sizeof(time_t) == 8) |
| 286 | + { |
| 287 | + TestDateTimeRoundtrip(_XPLATSTR("2038-01-19T03:13:07-00:01"), |
| 288 | + _XPLATSTR("2038-01-19T03:14:07Z")); // INT_MAX after subtacting 1 |
| 289 | + TestDateTimeRoundtrip(_XPLATSTR("2038-01-19T03:14:07-00:00"), _XPLATSTR("2038-01-19T03:14:07Z")); |
| 290 | + } |
| 291 | } |
| 292 | |
| 293 | TEST(parsing_time_iso8601_uses_each_timezone_digit) |
| 294 | @@ -456,11 +459,8 @@ SUITE(datetime) |
| 295 | _XPLATSTR("1971-01-01T00:60:00Z"), // minute too big |
| 296 | _XPLATSTR("1971-01-01T00:00:70Z"), // second too big |
| 297 | _XPLATSTR("1971-01-01T00:00:61Z"), |
| 298 | - _XPLATSTR("1969-01-01T00:00:00Z"), // underflow |
| 299 | -#ifdef _USE_32BIT_TIME_T |
| 300 | - _XPLATSTR("3000-01-01T00:00:01Z"), // overflow |
| 301 | -#endif |
| 302 | - _XPLATSTR("3001-01-01T00:00:00Z"), |
| 303 | + _XPLATSTR("1969-01-01T00:00:00Z"), // underflow |
| 304 | + _XPLATSTR("3001-01-01T00:00:00Z"), // overflow |
| 305 | _XPLATSTR("1970-01-01T00:00:00+00:01"), // time zone underflow |
| 306 | // _XPLATSTR("1970-01-01T00:00:00.Z"), // accepted as invalid timezone above |
| 307 | _XPLATSTR("1970-01-01T00:00:00+24:00"), // bad tzoffsets |