From 5a6d19be702b99a299ab5c5a8f61214dc48ce0f8 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 7 Aug 2024 09:13:13 +0200 Subject: [PATCH] Fix some defects detected by Coverity Scan (#22) * Clang Tidy fixes * Fix defects detected by Coverity Scan --------- Co-authored-by: cesaaargm --- src/core/libs/osnma_msg_receiver.cc | 12 ++++++------ src/core/system_parameters/gnss_crypto.cc | 5 +++-- .../osnma/gnss_crypto_test.cc | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/libs/osnma_msg_receiver.cc b/src/core/libs/osnma_msg_receiver.cc index e77260be5..ec58a3eef 100644 --- a/src/core/libs/osnma_msg_receiver.cc +++ b/src/core/libs/osnma_msg_receiver.cc @@ -271,7 +271,7 @@ void osnma_msg_receiver::process_osnma_message(const std::shared_ptr& { d_flag_PK_renewal = false; uint32_t final_GST = d_helper->compute_gst(osnma_msg->WN_sf0, osnma_msg->TOW_sf0); - double duration_hours = (final_GST - d_GST_PKR_PKREV_start) / 3600; + double duration_hours = (final_GST - d_GST_PKR_PKREV_start) / 3600.0; LOG(INFO) << "Galileo OSNMA: Public Key Renewal :: Finished at GST=" << duration_hours << ", Duration=" << duration_hours << " h"; std::cout << "Galileo OSNMA: Public Key Renewal :: Finished at GST=" << duration_hours << ", Duration=" << duration_hours << " h" << std::endl; } @@ -1400,7 +1400,7 @@ std::vector osnma_msg_receiver::build_message(Tag& tag) const // Add applicable NavData bits to message std::string applicable_nav_data = d_nav_data_manager->get_navigation_data(tag); std::vector applicable_nav_data_bytes = d_helper->bytes(applicable_nav_data); - tag.nav_data = applicable_nav_data; // update tag with applicable data + tag.nav_data = std::move(applicable_nav_data); // update tag with applicable data // Convert and add OSNMA_NavData bytes into the message, taking care of that NMAS has only 2 bits for (uint8_t byte : applicable_nav_data_bytes) @@ -1619,11 +1619,11 @@ bool osnma_msg_receiver::verify_macseq(const MACK_message& mack) // Assign relevant sequence based on subframe time if (mack.TOW % 60 < 30) // tried GST_Sf and it does not support the data present. { - applicable_sequence = sq1; + applicable_sequence = std::move(sq1); } else if (mack.TOW % 60 >= 30) { - applicable_sequence = sq2; + applicable_sequence = std::move(sq2); } if (mack.tag_and_info.size() != applicable_sequence.size() - 1) { @@ -1864,11 +1864,11 @@ std::vector osnma_msg_receiver::verify_macseq_new(const MACK_ // Assign relevant sequence based on subframe time if (mack.TOW % 60 < 30) // tried GST_Sf and it does not support the data present. { - applicable_sequence = sq1; + applicable_sequence = std::move(sq1); } else if (mack.TOW % 60 >= 30) { - applicable_sequence = sq2; + applicable_sequence = std::move(sq2); } if (mack.tag_and_info.size() != applicable_sequence.size() - 1) { diff --git a/src/core/system_parameters/gnss_crypto.cc b/src/core/system_parameters/gnss_crypto.cc index e664e4f50..27251a5a7 100644 --- a/src/core/system_parameters/gnss_crypto.cc +++ b/src/core/system_parameters/gnss_crypto.cc @@ -25,6 +25,7 @@ #include #include #include +#include #if USE_GNUTLS_FALLBACK #include @@ -625,7 +626,7 @@ std::vector Gnss_Crypto::compute_HMAC_SHA_256(const std::vector Gnss_Crypto::compute_CMAC_AES(const std::vector& k EVP_MAC_free(mac); aux.resize(output_length); - output = aux; + output = std::move(aux); #else // OpenSSL 1.x size_t mac_length = 0; // to hold the length of the MAC output diff --git a/src/tests/unit-tests/signal-processing-blocks/osnma/gnss_crypto_test.cc b/src/tests/unit-tests/signal-processing-blocks/osnma/gnss_crypto_test.cc index 2e536fb73..58dcc3f2f 100644 --- a/src/tests/unit-tests/signal-processing-blocks/osnma/gnss_crypto_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/osnma/gnss_crypto_test.cc @@ -22,6 +22,7 @@ #include #include #include +#include class GnssCryptoTest : public ::testing::Test { @@ -296,7 +297,7 @@ TEST(GnssCryptoTest, VerifySignatureP256) d_crypto->set_public_key(publicKey); ASSERT_TRUE(d_crypto->verify_signature_ecdsa_p256(message, signature)); - std::vector wrong_signature = signature; + std::vector wrong_signature = std::move(signature); wrong_signature[1] = 1; ASSERT_FALSE(d_crypto->verify_signature_ecdsa_p256(message, wrong_signature)); } @@ -340,7 +341,7 @@ TEST(GnssCryptoTest, VerifySignatureP521) d_crypto->set_public_key(publicKey); ASSERT_TRUE(d_crypto->verify_signature_ecdsa_p521(message, signature)); - std::vector wrong_signature = signature; + std::vector wrong_signature = std::move(signature); wrong_signature[1] = 1; ASSERT_FALSE(d_crypto->verify_signature_ecdsa_p521(message, wrong_signature)); }