Resolve warnings in VC-WIN32 build, which allows to add /WX.
It's argued that /WX allows to keep better focus on new code, which
motivates its comeback...
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4721)
diff --git a/test/asn1_encode_test.c b/test/asn1_encode_test.c
index 3b8d418..e9f459a 100644
--- a/test/asn1_encode_test.c
+++ b/test/asn1_encode_test.c
@@ -577,14 +577,14 @@
if (pp != NULL) {
if (lenbytes == 1) {
- *(*pp)++ = len;
+ *(*pp)++ = (unsigned char)len;
} else {
- *(*pp)++ = lenbytes - 1;
+ *(*pp)++ = (unsigned char)(lenbytes - 1);
if (lenbytes == 2) {
- *(*pp)++ = 0x80 | len;
+ *(*pp)++ = (unsigned char)(0x80 | len);
} else {
- *(*pp)++ = 0x80 | (len >> 8);
- *(*pp)++ = len & 0xff;
+ *(*pp)++ = (unsigned char)(0x80 | (len >> 8));
+ *(*pp)++ = (unsigned char)(len);
}
}
}
diff --git a/test/asn1_time_test.c b/test/asn1_time_test.c
index 874260e..113b6fb 100644
--- a/test/asn1_time_test.c
+++ b/test/asn1_time_test.c
@@ -79,22 +79,23 @@
/* ASSUMES SIGNED TIME_T */
static struct testdata tbl_testdata_neg[] = {
- { "19011213204552Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, -2147483648, -1, 0, },
+ { "19011213204552Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, INT_MIN, -1, 0, },
{ "691006121456Z", V_ASN1_UTCTIME, V_ASN1_UTCTIME, 1, -7472704, -1, 1, },
{ "19691006121456Z", V_ASN1_GENERALIZEDTIME, V_ASN1_UTCTIME, 1, -7472704, -1, 1, },
};
+/* explicit casts to time_t short warnings on systems with 32-bit time_t */
static struct testdata tbl_testdata_pos_64bit[] = {
- { "20380119031408Z", V_ASN1_GENERALIZEDTIME, V_ASN1_UTCTIME, 1, 0x80000000, 1, 1, },
- { "20380119031409Z", V_ASN1_GENERALIZEDTIME, V_ASN1_UTCTIME, 1, 0x80000001, 1, 1, },
- { "380119031408Z", V_ASN1_UTCTIME, V_ASN1_UTCTIME, 1, 0x80000000, 1, 1, },
- { "20500101120000Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, 2524651200, 1, 0, },
+ { "20380119031408Z", V_ASN1_GENERALIZEDTIME, V_ASN1_UTCTIME, 1, (time_t)0x80000000, 1, 1, },
+ { "20380119031409Z", V_ASN1_GENERALIZEDTIME, V_ASN1_UTCTIME, 1, (time_t)0x80000001, 1, 1, },
+ { "380119031408Z", V_ASN1_UTCTIME, V_ASN1_UTCTIME, 1, (time_t)0x80000000, 1, 1, },
+ { "20500101120000Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, (time_t)2524651200, 1, 0, },
};
/* ASSUMES SIGNED TIME_T */
static struct testdata tbl_testdata_neg_64bit[] = {
- { "19011213204551Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, -2147483649, -1, 0, },
- { "19000101120000Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, -2208945600, -1, 0, },
+ { "19011213204551Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, (time_t)-2147483649LL, -1, 0, },
+ { "19000101120000Z", V_ASN1_GENERALIZEDTIME, V_ASN1_GENERALIZEDTIME, 1, (time_t)-2208945600LL, -1, 0, },
};
/* A baseline time to compare to */
diff --git a/test/bad_dtls_test.c b/test/bad_dtls_test.c
index 102de24..5bd4e22 100644
--- a/test/bad_dtls_test.c
+++ b/test/bad_dtls_test.c
@@ -306,8 +306,8 @@
HMAC_Update(ctx, seq, 6);
HMAC_Update(ctx, &type, 1);
HMAC_Update(ctx, ver, 2); /* Version */
- lenbytes[0] = len >> 8;
- lenbytes[1] = len & 0xff;
+ lenbytes[0] = (unsigned char)(len >> 8);
+ lenbytes[1] = (unsigned char)(len);
HMAC_Update(ctx, lenbytes, 2); /* Length */
HMAC_Update(ctx, enc, len); /* Finally the data itself */
HMAC_Final(ctx, enc + len, NULL);
@@ -331,8 +331,8 @@
BIO_write(rbio, ver, 2);
BIO_write(rbio, epoch, 2);
BIO_write(rbio, seq, 6);
- lenbytes[0] = (len + sizeof(iv)) >> 8;
- lenbytes[1] = (len + sizeof(iv)) & 0xff;
+ lenbytes[0] = (unsigned char)((len + sizeof(iv)) >> 8);
+ lenbytes[1] = (unsigned char)(len + sizeof(iv));
BIO_write(rbio, lenbytes, 2);
BIO_write(rbio, iv, sizeof(iv));
diff --git a/test/clienthellotest.c b/test/clienthellotest.c
index acd27d4..8ba65ce 100644
--- a/test/clienthellotest.c
+++ b/test/clienthellotest.c
@@ -126,7 +126,7 @@
* We reset the creation time so that we don't discard the session as
* too old.
*/
- if (!TEST_true(SSL_SESSION_set_time(sess, time(NULL)))
+ if (!TEST_true(SSL_SESSION_set_time(sess, (long)time(NULL)))
|| !TEST_true(SSL_set_session(con, sess)))
goto end;
}
diff --git a/test/crltest.c b/test/crltest.c
index 738ca23..b964637 100644
--- a/test/crltest.c
+++ b/test/crltest.c
@@ -261,7 +261,7 @@
X509_STORE_CTX_set0_trusted_stack(ctx, roots);
X509_STORE_CTX_set0_crls(ctx, crls);
X509_VERIFY_PARAM_set_time(param, PARAM_TIME);
- if (!TEST_long_eq(X509_VERIFY_PARAM_get_time(param), PARAM_TIME))
+ if (!TEST_long_eq((long)X509_VERIFY_PARAM_get_time(param), PARAM_TIME))
goto err;
X509_VERIFY_PARAM_set_depth(param, 16);
if (flags)
diff --git a/test/ct_test.c b/test/ct_test.c
index 45dd2e9..21f1868 100644
--- a/test/ct_test.c
+++ b/test/ct_test.c
@@ -501,10 +501,11 @@
int success = 0;
CT_POLICY_EVAL_CTX *ct_policy_ctx = CT_POLICY_EVAL_CTX_new();
const time_t default_time = CT_POLICY_EVAL_CTX_get_time(ct_policy_ctx) /
- 1000;
+ 1000;
const time_t time_tolerance = 600; /* 10 minutes */
- if (!TEST_uint_le(fabs(difftime(time(NULL), default_time)), time_tolerance))
+ if (!TEST_uint_le((unsigned int)fabs(difftime(time(NULL), default_time)),
+ (unsigned int)time_tolerance))
goto end;
success = 1;
diff --git a/test/handshake_helper.c b/test/handshake_helper.c
index ad1b709..188ec9e 100644
--- a/test/handshake_helper.c
+++ b/test/handshake_helper.c
@@ -350,14 +350,14 @@
if ((*out)[i] == ',') {
if (!TEST_int_gt(i - 1, prefix))
goto err;
- (*out)[prefix] = i - 1 - prefix;
+ (*out)[prefix] = (unsigned char)(i - 1 - prefix);
prefix = i;
}
i++;
}
if (!TEST_int_gt(len, prefix))
goto err;
- (*out)[prefix] = len - prefix;
+ (*out)[prefix] = (unsigned char)(len - prefix);
return 1;
err:
diff --git a/test/packettest.c b/test/packettest.c
index 98b9ec4..716dec3 100644
--- a/test/packettest.c
+++ b/test/packettest.c
@@ -352,7 +352,7 @@
unsigned int i;
PACKET pkt, short_pkt, subpkt = {0};
- buf1[0] = len;
+ buf1[0] = (unsigned char)len;
for (i = 1; i < BUF_LEN; i++)
buf1[i] = (i * 2) & 0xff;
@@ -422,7 +422,7 @@
unsigned int i;
PACKET pkt, exact_pkt, subpkt = {0};
- buf1[0] = len;
+ buf1[0] = (unsigned char)len;
for (i = 1; i < BUF_LEN; i++)
buf1[i] = (i * 2) & 0xff;
diff --git a/test/sanitytest.c b/test/sanitytest.c
index e9afb44..5954f7e 100644
--- a/test/sanitytest.c
+++ b/test/sanitytest.c
@@ -8,9 +8,8 @@
*/
#include <string.h>
-#include "internal/numbers.h"
-
#include "testutil.h"
+#include "internal/numbers.h"
static int test_sanity_null_zero(void)
{
diff --git a/test/ssltest_old.c b/test/ssltest_old.c
index ebe052f..a4e596a 100644
--- a/test/ssltest_old.c
+++ b/test/ssltest_old.c
@@ -281,7 +281,7 @@
OPENSSL_free(out);
return NULL;
}
- out[start] = i - start;
+ out[start] = (unsigned char)(i - start);
start = i + 1;
} else
out[i + 1] = in[i];
diff --git a/test/testutil/driver.c b/test/testutil/driver.c
index 2c28a73..48593f9 100644
--- a/test/testutil/driver.c
+++ b/test/testutil/driver.c
@@ -17,6 +17,10 @@
#include "internal/nelem.h"
#include <openssl/bio.h>
+#ifdef _WIN32
+# define strdup _strdup
+#endif
+
/*
* Declares the structures needed to register each test case function.
*/