]> granicus.if.org Git - libevent/commitdiff
test: fix util/date_rfc1123 under win32
authorAzat Khuzhin <a3at.mail@gmail.com>
Thu, 22 Dec 2016 11:55:33 +0000 (14:55 +0300)
committerAzat Khuzhin <a3at.mail@gmail.com>
Thu, 22 Dec 2016 15:10:24 +0000 (18:10 +0300)
Refs: #417
v2: check when gmtime() returns NULL
v3: fix overflow cases

evutil_time.c
test/regress_util.c

index da5c745375ae5966c0cff55cf7ef65c0ec52baee..00fd5fb4f77b9af2bc7a2407d91ab4e80771df01 100644 (file)
@@ -162,6 +162,7 @@ evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm)
        /* If `tm` is null, set system's current time. */
        if (tm == NULL) {
 #ifdef _WIN32
+               /** TODO: detect _gmtime64()/_gmtime64_s() */
                tm = gmtime(&t);
 #else
                gmtime_r(&t, &sys);
index 12f76e61016abd85df38738ac91997c73c1606e2..ef6a1487aae2a88ff6ae1d15b5d5b5a3980d2e39 100644 (file)
@@ -1379,9 +1379,15 @@ end:
 }
 
 static void
-create_tm_from_unix_epoch(struct tm *cur_p, const time_t t) {
+create_tm_from_unix_epoch(struct tm *cur_p, const time_t t)
+{
 #ifdef _WIN32
-       cur_p = gmtime(&t);
+       struct tm *tmp = gmtime(&t);
+       if (!tmp) {
+               fprintf(stderr, "gmtime: %s (%i)", strerror(errno), (int)t);
+               exit(1);
+       }
+       *cur_p = *tmp;
 #else
        gmtime_r(&t, cur_p);
 #endif
@@ -1405,9 +1411,13 @@ static struct date_rfc1123_case {
        {  1255132800, "Sat, 10 Oct 2009 00:00:00 GMT"},
        {  1289433600, "Thu, 11 Nov 2010 00:00:00 GMT"},
        {  1323648000, "Mon, 12 Dec 2011 00:00:00 GMT"},
+#ifndef _WIN32
+       /** In win32 case we have max   "23:59:59 January 18, 2038, UTC" for time32 */
        {  4294967296, "Sun, 07 Feb 2106 06:28:16 GMT"} /* 2^32 */,
+       /** In win32 case we have max "23:59:59, December 31, 3000, UTC" for time64 */
        {253402300799, "Fri, 31 Dec 9999 23:59:59 GMT"} /* long long future no one can imagine */,
        {  1456704000, "Mon, 29 Feb 2016 00:00:00 GMT"} /* leap year */,
+#endif
        {  1435708800, "Wed, 01 Jul 2015 00:00:00 GMT"} /* leap second */,
        {  1481866376, "Fri, 16 Dec 2016 05:32:56 GMT"} /* the time this test case is generated */,
        {0, ""} /* end of test cases. */