From 85365a14974c352da95d27bbdc365d87f9f9cc4a Mon Sep 17 00:00:00 2001 From: Fred Gylys-Colwell Date: Tue, 21 Mar 2017 15:09:02 -0700 Subject: [PATCH] Fix or ignore compiler warnings Merge from Widevine repo of http://go/wvgerrit/24688 b/35466719 Change-Id: If89f0cad0c61f37536a84f8dadaf08072356343a --- .../cdm/core/src/crypto_session.cpp | 2 +- .../core/src/oemcrypto_adapter_dynamic.cpp | 8 ++--- .../oemcrypto/test/oec_session_util.cpp | 10 +++---- .../oemcrypto/test/oec_session_util.h | 8 ++--- .../oemcrypto/test/oemcrypto_test.cpp | 30 +++++++++---------- libwvdrmengine/test/unit/Android.mk | 8 +++++ 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 0713b65a..108356ed 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -106,7 +106,7 @@ void CryptoSession::Init() { } void CryptoSession::Terminate() { - LOGE("CryptoSession::Terminate: initialized_=%d, session_count_=%d", + LOGV("CryptoSession::Terminate: initialized_=%d, session_count_=%d", initialized_, session_count_); AutoLock auto_lock(crypto_lock_); if (session_count_ > 0) { diff --git a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp index 8e1059c7..6e5c6384 100644 --- a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp +++ b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp @@ -334,7 +334,7 @@ void clear_cache_function(void *page, size_t len) { // are true, and use "#ifndef USED_BUILTIN_CLEAR_CACHE" instead of #else. #ifdef __has_builtin #if __has_builtin(__builtin___clear_cache) -#pragma message "clear_cache_function is using __builtin___clear_cache." +#pragma message "(info): clear_cache_function is using __builtin___clear_cache." #define USED_BUILTIN_CLEAR_CACHE char *begin = static_cast(page); char *end = begin + len; @@ -343,7 +343,7 @@ void clear_cache_function(void *page, size_t len) { #endif #ifndef USED_BUILTIN_CLEAR_CACHE #if __arm__ -#pragma message "clear_cache_function is using arm asm." +#pragma message "(info): clear_cache_function is using arm asm." // ARM Cache Flush System Call: char *begin = static_cast(page); char *end = begin + len; @@ -361,7 +361,7 @@ void clear_cache_function(void *page, size_t len) { : "r0", "r1", "r7" ); #elif __mips__ -#pragma message "clear_cache_function is using mips asm." +#pragma message "(info): clear_cache_function is using mips asm." int result = syscall(__NR_cacheflush, page, len, ICACHE); if (result) { fprintf(stderr, "cacheflush failed!: errno=%d %s\n", errno, @@ -369,7 +369,7 @@ void clear_cache_function(void *page, size_t len) { exit(-1); // TODO(fredgc): figure out more graceful error handling. } #else -#pragma message "clear_cache_function is not doing anything." +#pragma message "(info): clear_cache_function is not doing anything." // TODO(fredgc): silence warning about unused variables. #endif #endif diff --git a/libwvdrmengine/oemcrypto/test/oec_session_util.cpp b/libwvdrmengine/oemcrypto/test/oec_session_util.cpp index 074dbb8c..581c1564 100644 --- a/libwvdrmengine/oemcrypto/test/oec_session_util.cpp +++ b/libwvdrmengine/oemcrypto/test/oec_session_util.cpp @@ -93,7 +93,7 @@ Session::Session() num_keys_(4) { // Most tests only use 4 keys. // Other tests will explicitly call set_num_keys. // Stripe the padded message. - for (int i = 0; i < sizeof(padded_message_.padding); i++) { + for (size_t i = 0; i < sizeof(padded_message_.padding); i++) { padded_message_.padding[i] = i % 0x100; } } @@ -424,7 +424,7 @@ void Session::VerifyClientSignature(size_t data_length) { // In the real world, a message should be signed by the client and // verified by the server. This simulates that. vector data(data_length); - for (int i = 0; i < data.size(); i++) data[i] = i % 0xFF; + for (size_t i = 0; i < data.size(); i++) data[i] = i % 0xFF; OEMCryptoResult sts; size_t gen_signature_length = 0; sts = OEMCrypto_GenerateSignature(session_id(), &data[0], data.size(), NULL, @@ -580,7 +580,7 @@ void Session::LoadOEMCert(bool verify_cert) { ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER, OEMCrypto_GetOEMPublicCertificate(session_id(), NULL, &public_cert_length)); - ASSERT_GT(public_cert_length, 0); + ASSERT_LT(0u, public_cert_length); public_cert.resize(public_cert_length); ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_GetOEMPublicCertificate(session_id(), &public_cert[0], @@ -674,7 +674,6 @@ void Session::RewrapRSAKey(const struct RSAPrivateKeyMessage& encrypted, } } void Session::RewrapRSAKey30(const struct RSAPrivateKeyMessage& encrypted, - size_t message_size, const std::vector& encrypted_message_key, vector* wrapped_key, bool force) { size_t wrapped_key_length = 0; @@ -861,8 +860,7 @@ void Session::UpdateUsageEntry(std::vector* header_buffer) { &encrypted_usage_entry_[0], &entry_buffer_length)); } -void Session::DeactivateUsageEntry(const std::string& pst, - OEMCryptoResult expect_result) { +void Session::DeactivateUsageEntry(const std::string& pst) { ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_DeactivateUsageEntry( session_id(), reinterpret_cast(pst.c_str()), diff --git a/libwvdrmengine/oemcrypto/test/oec_session_util.h b/libwvdrmengine/oemcrypto/test/oec_session_util.h index 8bfc4e36..578e5e85 100644 --- a/libwvdrmengine/oemcrypto/test/oec_session_util.h +++ b/libwvdrmengine/oemcrypto/test/oec_session_util.h @@ -248,7 +248,6 @@ class Session { // Calls OEMCrypto_RewrapDeviceRSAKey30 with the given provisioning response // message. If force is true, we assert that the key loads successfully. void RewrapRSAKey30(const struct RSAPrivateKeyMessage& encrypted, - size_t message_size, const std::vector& encrypted_message_key, vector* wrapped_key, bool force); // Loads the specified wrapped_rsa_key into OEMCrypto, and then runs @@ -269,8 +268,7 @@ class Session { // Update the usage entry and save the header to the specified buffer. void UpdateUsageEntry(std::vector* header_buffer); // Deactivate this session's usage entry. - void DeactivateUsageEntry(const std::string& pst, - OEMCryptoResult expect_result = OEMCrypto_SUCCESS); + void DeactivateUsageEntry(const std::string& pst); // The usage entry number for this session's usage entry. uint32_t usage_entry_number() const { return usage_entry_number_; } void set_usage_entry_number(uint32_t v) { usage_entry_number_ = v; } @@ -330,7 +328,7 @@ class Session { void set_num_keys(int num_keys) { num_keys_ = num_keys; } // The current number of keys to use in the license(), encrypted_license() // and key_array(). - int num_keys() const { return num_keys_; } + unsigned int num_keys() const { return num_keys_; } // Set the size of the buffer used the encrypted license. // Must be between sizeof(MessageData) and kMaxMessageSize. @@ -355,7 +353,7 @@ class Session { size_t message_size_; // How much of the padded message to use. OEMCrypto_KeyObject key_array_[kMaxNumKeys]; std::vector signature_; - int num_keys_; + unsigned int num_keys_; vector encrypted_usage_entry_; uint32_t usage_entry_number_; string pst_; diff --git a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp index e5ab91b6..7e13ab7e 100644 --- a/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp +++ b/libwvdrmengine/oemcrypto/test/oemcrypto_test.cpp @@ -277,7 +277,7 @@ TEST_F(OEMCryptoClientTest, GetRandomLargeBuffer) { // We don't have enough data to see that the data is really random, // so we'll just do a spot check that two calls don't return the same values. int count = 0; - for (int i = 0; i < size; i++) { + for (size_t i = 0; i < size; i++) { if (data1[i] == data2[i]) count++; } ASSERT_LE(count, 3); // P(count > 3) = 1/256^3 = 6e-8. @@ -505,7 +505,7 @@ TEST_F(OEMCryptoKeyboxTest, GenerateDerivedKeysFromKeyboxLargeBuffer) { vector mac_context(kMaxMessageSize); vector enc_context(kMaxMessageSize); // Stripe the data so the two vectors are not identical, and not all zeroes. - for (int i = 0; i < kMaxMessageSize; i++) { + for (size_t i = 0; i < kMaxMessageSize; i++) { mac_context[i] = i % 0x100; enc_context[i] = (3 * i) % 0x100; } @@ -764,8 +764,7 @@ class OEMCryptoSessionTests : public OEMCryptoClientTest { ASSERT_NO_FATAL_FAILURE( s.MakeRSACertificate(&encrypted, sizeof(encrypted), &signature, allowed_schemes, encoded_rsa_key_, &message_key)); - ASSERT_NO_FATAL_FAILURE(s.RewrapRSAKey30(encrypted, sizeof(encrypted), - encrypted_message_key, + ASSERT_NO_FATAL_FAILURE(s.RewrapRSAKey30(encrypted, encrypted_message_key, &wrapped_rsa_key_, force)); // Verify that the clear key is not contained in the wrapped key. // It should be encrypted. @@ -946,7 +945,7 @@ TEST_F(OEMCryptoSessionTests, ClientSignatureLargeBuffer) { ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", false)); vector context(kMaxMessageSize); - for (int i = 0; i < kMaxMessageSize; i++) { + for (size_t i = 0; i < kMaxMessageSize; i++) { context[i] = i % 0x100; } static const uint32_t SignatureBufferMaxLength = 256; @@ -1180,11 +1179,11 @@ class SessionTestAlternateVerification : public OEMCryptoSessionTests, public: virtual void SetUp() { OEMCryptoSessionTests::SetUp(); - target_api_ = GetParam(); + target_api_ = static_cast(GetParam()); } protected: - int target_api_; + uint32_t target_api_; }; TEST_P(SessionTestAlternateVerification, LoadKeys) { @@ -1197,7 +1196,7 @@ TEST_P(SessionTestAlternateVerification, LoadKeys) { if (target_api_ > 8 && target_api_ < 100) { snprintf(buffer, 5, "kc%02d", target_api_); } - for (int i = 0; i < s.num_keys(); i++) { + for (size_t i = 0; i < s.num_keys(); i++) { memcpy(s.license().keys[i].control.verification, buffer, 4); } ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); @@ -1386,7 +1385,7 @@ TEST_F(OEMCryptoSessionTests, Minimum20KeysAPI12) { ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(0, 0, 0)); ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys()); - for (int key_index = 0; key_index < kMaxNumKeys; key_index++) { + for (size_t key_index = 0; key_index < kMaxNumKeys; key_index++) { bool kSelectKeyFirst = true; ASSERT_NO_FATAL_FAILURE( s.TestDecryptCTR(kSelectKeyFirst, OEMCrypto_SUCCESS, key_index)); @@ -1707,7 +1706,8 @@ class OEMCryptoSessionTestsDecryptTests // Partial block. Don't increment iv. Compute next block offset. block_offset = block_offset + size; } else { - EXPECT_EQ(AES_BLOCK_SIZE, block_offset + size); + EXPECT_EQ(static_cast(AES_BLOCK_SIZE), + block_offset + size); // Full block. Increment iv, and set offset to 0 for next block. ctr128_inc64(1, iv); block_offset = 0; @@ -1751,7 +1751,7 @@ class OEMCryptoSessionTestsDecryptTests if (decrypt_inplace_) { // Use same buffer for input and output. // Copy the useful data from encryptedData to output_buffer, which // will be the same as input_buffer. Leave the 0xaa padding at the end. - for(int i=0; i < total_size_; i++) output_buffer[i] = encryptedData[i]; + for(size_t i=0; i < total_size_; i++) output_buffer[i] = encryptedData[i]; // Now let input_buffer point to the same data. input_buffer = &output_buffer[0]; } else { @@ -2479,7 +2479,7 @@ TEST_F(OEMCryptoLoadsCertificate, TestLargeRSAKey3072) { // Devices that load certificates, should at least support RSA 2048 keys. TEST_F(OEMCryptoLoadsCertificate, SupportsCertificatesAPI13) { - ASSERT_NE(0, + ASSERT_NE(0u, OEMCrypto_Supports_RSA_2048bit & OEMCrypto_SupportedCertificates()) << "Supported certificates is only " << OEMCrypto_SupportedCertificates(); } @@ -2686,7 +2686,7 @@ TEST_F(OEMCryptoUsesCertificate, GenerateDerivedKeysLargeBuffer) { vector mac_context(kMaxMessageSize); vector enc_context(kMaxMessageSize); // Stripe the data so the two vectors are not identical, and not all zeroes. - for (int i = 0; i < kMaxMessageSize; i++) { + for (size_t i = 0; i < kMaxMessageSize; i++) { mac_context[i] = i % 0x100; enc_context[i] = (3 * i) % 0x100; } @@ -3061,7 +3061,7 @@ class OEMCryptoCastReceiverTest : public OEMCryptoLoadsCertificateAlternates { // CAST Receivers should report that they support cast certificates. TEST_F(OEMCryptoCastReceiverTest, SupportsCertificatesAPI13) { - ASSERT_NE(0, OEMCrypto_Supports_RSA_CAST & OEMCrypto_SupportedCertificates()); + ASSERT_NE(0u, OEMCrypto_Supports_RSA_CAST & OEMCrypto_SupportedCertificates()); } // # PKCS#1 v1.5 Signature Example 15.1 @@ -4607,7 +4607,7 @@ TEST_F(UsageTableTest, TwoHundredEntries) { s1.get_nonce(), pst1)); ASSERT_NO_FATAL_FAILURE(s1.EncryptAndSign()); ASSERT_NO_FATAL_FAILURE(s1.CreateNewUsageEntry()); - ASSERT_EQ(s1.usage_entry_number(), 0); + ASSERT_EQ(0u, s1.usage_entry_number()); time_t start = time(NULL); ASSERT_NO_FATAL_FAILURE(s1.LoadTestKeys(pst1, new_mac_keys_)); ASSERT_NO_FATAL_FAILURE(s1.UpdateUsageEntry(&encrypted_usage_header_)); diff --git a/libwvdrmengine/test/unit/Android.mk b/libwvdrmengine/test/unit/Android.mk index 732886c8..983eb389 100644 --- a/libwvdrmengine/test/unit/Android.mk +++ b/libwvdrmengine/test/unit/Android.mk @@ -34,6 +34,10 @@ LOCAL_MODULE := libwvdrmengine_test LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_OWNER := widevine + +LOCAL_PROPRIETARY_MODULE := true + include $(BUILD_EXECUTABLE) # ----------------------------------------------------------------------------- @@ -75,4 +79,8 @@ LOCAL_MODULE := libwvdrmengine_hidl_test LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_OWNER := widevine + +LOCAL_PROPRIETARY_MODULE := true + include $(BUILD_EXECUTABLE)