Work around a 32-bit mingw failure
Passing the return value from gmtime() directly to mktime() was producing
incorrect results under windows (but not under wine) when built with mingw
32-bit (but not VC-WIN32). We implement a workaround for this.
@@ -161,21 +161,31 @@ static int test_HDR_set1_recipient(void)
static int execute_HDR_update_messageTime_test(CMP_HDR_TEST_FIXTURE *fixture)
{
- struct tm hdrtm;
+ struct tm hdrtm, tmptm;
time_t hdrtime, before, after, now;
now = time(NULL);
- before = mktime(gmtime(&now));
+ /*
+ * Trial and error reveals that passing the return value from gmtime
+ * directly to mktime in a mingw 32 bit build gives unexpected results. To
+ * work around this we take a copy of the return value first.
+ */
+ tmptm = *gmtime(&now);
+ before = mktime(&tmptm);
+
if (!TEST_true(ossl_cmp_hdr_update_messageTime(fixture->hdr)))
return 0;
if (!TEST_true(ASN1_TIME_to_tm(fixture->hdr->messageTime, &hdrtm)))
return 0;
hdrtime = mktime(&hdrtm);
+
if (!TEST_time_t_le(before, hdrtime))
return 0;
now = time(NULL);
- after = mktime(gmtime(&now));
+ tmptm = *gmtime(&now);
+ after = mktime(&tmptm);
+
return TEST_time_t_le(hdrtime, after);
}
