clang-tidy: Enable bugprone-assignment-in-if
Modified code to address issues flagged by this check.
Tested: Build and unit tests passed successfully.
Change-Id: I3b5f7c29fa38fc39da06e27488d70866006695c9
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/.clang-tidy b/.clang-tidy
index df0114b..3322c6f 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -2,6 +2,7 @@
-*,
bugprone-argument-comment,
bugprone-assert-side-effect,
+bugprone-assignment-in-if,
bugprone-bad-signal-to-kill-thread,
bugprone-bool-pointer-implicit-conversion,
bugprone-branch-clone,
diff --git a/certificate.cpp b/certificate.cpp
index 67c5aad..5e4ef9c 100644
--- a/certificate.cpp
+++ b/certificate.cpp
@@ -510,12 +510,12 @@
issuer(issuerBuffer);
std::vector<std::string> keyUsageList;
- ASN1_BIT_STRING* usage;
// Go through each usage in the bit string and convert to
// corresponding string value
- if ((usage = static_cast<ASN1_BIT_STRING*>(
- X509_get_ext_d2i(&cert, NID_key_usage, nullptr, nullptr))))
+ ASN1_BIT_STRING* usage = static_cast<ASN1_BIT_STRING*>(
+ X509_get_ext_d2i(&cert, NID_key_usage, nullptr, nullptr));
+ if (usage != nullptr)
{
for (auto i = 0; i < usage->length; ++i)
{
@@ -530,9 +530,9 @@
}
}
- EXTENDED_KEY_USAGE* extUsage;
- if ((extUsage = static_cast<EXTENDED_KEY_USAGE*>(
- X509_get_ext_d2i(&cert, NID_ext_key_usage, nullptr, nullptr))))
+ EXTENDED_KEY_USAGE* extUsage = static_cast<EXTENDED_KEY_USAGE*>(
+ X509_get_ext_d2i(&cert, NID_ext_key_usage, nullptr, nullptr));
+ if (extUsage == nullptr)
{
for (int i = 0; i < sk_ASN1_OBJECT_num(extUsage); i++)
{
diff --git a/certs_manager.cpp b/certs_manager.cpp
index 9d828c1..dc991d5 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -904,9 +904,9 @@
}
}
- FILE* fp = nullptr;
+ FILE* fp = std::fopen(filePath.c_str(), "w");
- if ((fp = std::fopen(filePath.c_str(), "w")) == nullptr)
+ if (fp == nullptr)
{
lg2::error(
"Error opening the file to write the CSR, FILENAME:{FILENAME}",