From c45559177afdcc1010a16df08481a63a11df04aa Mon Sep 17 00:00:00 2001 From: "John W. Bruce" Date: Wed, 10 Nov 2021 16:16:47 -0800 Subject: [PATCH] Fix -Wshorten-64-to-32 errors in test code (This is a merge of http://go/wvgerrit/134316.) This patch fixes code that would trigger -Wshorten-64-to-32 by implicitly narrowing a variable from 64 to 32 bits. Most of the time, it does this by making the implicit conversion explicit. Occasionally, where it makes sense, it does this by expanding the code to operate on a 64-bit value. This patch removes LicenseKeysTest::NumContentKeys(), which no one was using, as all the tests access content_key_count_ directly. Bug: 194971260 Test: x86-64 Change-Id: Iae7685c10b9db989253b349cab693728b438798d --- libwvdrmengine/cdm/core/test/duration_use_case_test.cpp | 4 +++- libwvdrmengine/cdm/core/test/http_socket_test.cpp | 3 ++- libwvdrmengine/cdm/core/test/license_keys_unittest.cpp | 2 -- libwvdrmengine/cdm/core/test/test_base.cpp | 4 ++-- libwvdrmengine/cdm/core/test/url_request.cpp | 4 ++-- libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libwvdrmengine/cdm/core/test/duration_use_case_test.cpp b/libwvdrmengine/cdm/core/test/duration_use_case_test.cpp index 4c991ee1..8fc987d2 100644 --- a/libwvdrmengine/cdm/core/test/duration_use_case_test.cpp +++ b/libwvdrmengine/cdm/core/test/duration_use_case_test.cpp @@ -207,7 +207,9 @@ class CdmDurationTest : public WvCdmTestBaseWithEngine, void SleepUntil(uint64_t desired_rental_time) { const uint64_t rental_time = CurrentRentalTime(); if (desired_rental_time >= rental_time) { - TestSleep::Sleep(desired_rental_time - rental_time); + const unsigned int sleep_time = + static_cast(desired_rental_time - rental_time); + TestSleep::Sleep(sleep_time); } else { LOGW("Test Clock skew sleeping from rental clock time %" PRIu64 " to %" PRIu64, diff --git a/libwvdrmengine/cdm/core/test/http_socket_test.cpp b/libwvdrmengine/cdm/core/test/http_socket_test.cpp index 974a1e38..b7f801f7 100644 --- a/libwvdrmengine/cdm/core/test/http_socket_test.cpp +++ b/libwvdrmengine/cdm/core/test/http_socket_test.cpp @@ -73,7 +73,8 @@ class HttpSocketTest : public testing::Test { // append data request.append(data); - socket_->WriteAndLogErrors(request.c_str(), request.size(), kTimeout); + socket_->WriteAndLogErrors(request.c_str(), + static_cast(request.size()), kTimeout); LOGD("request: %s", request.c_str()); return true; diff --git a/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp b/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp index 3d339fa1..8a8f7b91 100644 --- a/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/license_keys_unittest.cpp @@ -201,8 +201,6 @@ class LicenseKeysTest : public ::testing::Test { EXPECT_EQ(key_usage.generic_verify, verify == kKeyFlagTrue); } - virtual int NumContentKeys() { return content_key_count_; } - virtual void StageContentKeys() { content_key_count_ = 0; AddContentKey(ck_sw_crypto, true, KeyContainer::SW_SECURE_CRYPTO); diff --git a/libwvdrmengine/cdm/core/test/test_base.cpp b/libwvdrmengine/cdm/core/test/test_base.cpp index 430778ce..1a487f08 100644 --- a/libwvdrmengine/cdm/core/test/test_base.cpp +++ b/libwvdrmengine/cdm/core/test/test_base.cpp @@ -809,11 +809,11 @@ std::string MakePSSH(const std::string& serialized_header) { size_t data_size = serialized_header.size(); size_t atom_size = data_size + system_id_size + 4 * 4; - std::string pssh = EncodeUint32(atom_size); + std::string pssh = EncodeUint32(static_cast(atom_size)); pssh.append("pssh"); pssh.append(EncodeUint32(version)); pssh.append(system_id); - pssh.append(EncodeUint32(data_size)); + pssh.append(EncodeUint32(static_cast(data_size))); pssh.append(serialized_header); return pssh; } diff --git a/libwvdrmengine/cdm/core/test/url_request.cpp b/libwvdrmengine/cdm/core/test/url_request.cpp index 42a4c126..ed25afa7 100644 --- a/libwvdrmengine/cdm/core/test/url_request.cpp +++ b/libwvdrmengine/cdm/core/test/url_request.cpp @@ -203,8 +203,8 @@ bool UrlRequest::PostRequestWithPath(const std::string& path, request.append(data); - const int ret = socket_.WriteAndLogErrors(request.c_str(), request.size(), - kWriteTimeoutMs); + const int ret = socket_.WriteAndLogErrors( + request.c_str(), static_cast(request.size()), kWriteTimeoutMs); LOGV("HTTP request: (%zu): %s", request.size(), b2a_hex(request).c_str()); return ret != -1; } diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index ef5c364a..cc87ca8d 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -3230,7 +3230,7 @@ TEST_P(OEMCryptoLicenseTest, AntiRollbackHardwareRequired) { TEST_P(OEMCryptoLicenseTest, MinimumKeys) { const size_t num_keys = GetResourceValue(kMaxKeysPerSession); ASSERT_LE(num_keys, kMaxNumKeys) << "Test constants need updating."; - license_messages_.set_num_keys(num_keys); + license_messages_.set_num_keys(static_cast(num_keys)); ASSERT_NO_FATAL_FAILURE(session_.GenerateNonce()); ASSERT_NO_FATAL_FAILURE(license_messages_.SignAndVerifyRequest()); ASSERT_NO_FATAL_FAILURE(license_messages_.CreateDefaultResponse()); @@ -3258,7 +3258,7 @@ void TestMaxKeys(SessionUtil* util, size_t num_keys_per_session) { new LicenseRoundTrip(sessions[i].get()))); const size_t num_keys = std::min(max_total_keys - total_keys, num_keys_per_session); - licenses[i]->set_num_keys(num_keys); + licenses[i]->set_num_keys(static_cast(num_keys)); total_keys += num_keys; ASSERT_NO_FATAL_FAILURE(sessions[i]->open()); ASSERT_NO_FATAL_FAILURE(util->InstallTestRSAKey(sessions[i].get()));