Enable readability-implicit-bool-conversion checks
These checks ensure that we're not implicitly converting ints or
pointers into bools, which makes the code easier to read.
Tested:
Ran series through redfish service validator. No changes observed.
UUID failing in Qemu both before and after.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I1ca0be980d136bd4e5474341f4fd62f2f6bbdbae
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 9bc79ad..8519b5a 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -31,7 +31,7 @@
inline int onPropertyUpdate(sd_bus_message* m, void* userdata,
sd_bus_error* retError)
{
- if (retError == nullptr || sd_bus_error_is_set(retError))
+ if (retError == nullptr || (sd_bus_error_is_set(retError) != 0))
{
BMCWEB_LOG_ERROR << "Got sdbus error on match";
return 0;
diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp
index 30186b6..73c315f 100644
--- a/include/hostname_monitor.hpp
+++ b/include/hostname_monitor.hpp
@@ -35,7 +35,7 @@
inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
sd_bus_error* retError)
{
- if (retError == nullptr || sd_bus_error_is_set(retError))
+ if (retError == nullptr || (sd_bus_error_is_set(retError) != 0))
{
BMCWEB_LOG_ERROR << "Got sdbus error on match";
return 0;
@@ -101,7 +101,7 @@
ASN1_IA5STRING* asn1 = static_cast<ASN1_IA5STRING*>(
X509_get_ext_d2i(cert, NID_netscape_comment, nullptr, nullptr));
- if (asn1)
+ if (asn1 != nullptr)
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
std::string_view comment(reinterpret_cast<const char*>(asn1->data),
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index 740e218..3970992 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -53,7 +53,7 @@
for (const char c : value)
{
// Keep alphanumeric and other accepted characters intact
- if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
+ if ((isalnum(c) != 0) || c == '-' || c == '_' || c == '.' || c == '~')
{
escaped << c;
continue;
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index b39bada..7dccbd8 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -279,7 +279,7 @@
{
for (const auto& id : refRids)
{
- if (lockTable.erase(id))
+ if (lockTable.erase(id) != 0U)
{
BMCWEB_LOG_DEBUG << "Removing the locks with transaction ID : "
<< id;
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 6861571..b457935 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -656,16 +656,16 @@
else if (argCode == "b")
{
// lots of ways bool could be represented here. Try them all
- int boolInt = false;
+ int boolInt = 0;
if (intValue != nullptr)
{
if (*intValue == 1)
{
- boolInt = true;
+ boolInt = 1;
}
else if (*intValue == 0)
{
- boolInt = false;
+ boolInt = 0;
}
else
{
@@ -1025,7 +1025,7 @@
while (true)
{
- r = sd_bus_message_at_end(m.get(), false);
+ r = sd_bus_message_at_end(m.get(), 0);
if (r < 0)
{
BMCWEB_LOG_ERROR << "sd_bus_message_at_end failed";
@@ -1483,7 +1483,7 @@
transaction->methodFailed = true;
const sd_bus_error* e = m2.get_error();
- if (e)
+ if (e != nullptr)
{
setErrorResponse(
transaction->res,
@@ -2002,10 +2002,12 @@
boost::beast::http::
status::
forbidden,
- (e) ? e->name
+ (e) != nullptr
+ ? e->name
: ec.category()
.name(),
- (e) ? e->message
+ (e) != nullptr
+ ? e->message
: ec.message());
}
else
diff --git a/include/security_headers.hpp b/include/security_headers.hpp
index 966fbdf..828a44c 100644
--- a/include/security_headers.hpp
+++ b/include/security_headers.hpp
@@ -25,7 +25,7 @@
"mode=block");
res.addHeader("X-Content-Type-Options", "nosniff");
- if (!bmcwebInsecureDisableXssPrevention)
+ if (bmcwebInsecureDisableXssPrevention == 0)
{
res.addHeader("Content-Security-Policy", "default-src 'none'; "
"img-src 'self' data:; "
diff --git a/include/ssl_key_handler.hpp b/include/ssl_key_handler.hpp
index fcb79f2..30145f8 100644
--- a/include/ssl_key_handler.hpp
+++ b/include/ssl_key_handler.hpp
@@ -40,7 +40,7 @@
{
// Create an empty X509_STORE structure for certificate validation.
X509_STORE* x509Store = X509_STORE_new();
- if (!x509Store)
+ if (x509Store == nullptr)
{
BMCWEB_LOG_ERROR << "Error occurred during X509_STORE_new call";
return false;
@@ -48,7 +48,7 @@
// Load Certificate file into the X509 structure.
X509_STORE_CTX* storeCtx = X509_STORE_CTX_new();
- if (!storeCtx)
+ if (storeCtx == nullptr)
{
BMCWEB_LOG_ERROR << "Error occurred during X509_STORE_CTX_new call";
X509_STORE_free(x509Store);
@@ -147,7 +147,7 @@
EVP_PKEY_CTX* pkeyCtx =
EVP_PKEY_CTX_new_from_pkey(nullptr, pkey, nullptr);
- if (!pkeyCtx)
+ if (pkeyCtx == nullptr)
{
std::cerr << "Unable to allocate pkeyCtx " << ERR_get_error()
<< "\n";
@@ -198,7 +198,7 @@
inline X509* loadCert(const std::string& filePath)
{
BIO* certFileBio = BIO_new_file(filePath.c_str(), "rb");
- if (!certFileBio)
+ if (certFileBio == nullptr)
{
BMCWEB_LOG_ERROR << "Error occured during BIO_new_file call, "
<< "FILE= " << filePath;
@@ -206,7 +206,7 @@
}
X509* cert = X509_new();
- if (!cert)
+ if (cert == nullptr)
{
BMCWEB_LOG_ERROR << "Error occured during X509_new call, "
<< ERR_get_error();
@@ -214,7 +214,7 @@
return nullptr;
}
- if (!PEM_read_bio_X509(certFileBio, &cert, nullptr, nullptr))
+ if (PEM_read_bio_X509(certFileBio, &cert, nullptr, nullptr) == nullptr)
{
BMCWEB_LOG_ERROR << "Error occured during PEM_read_bio_X509 call, "
<< "FILE= " << filePath;
@@ -235,7 +235,7 @@
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
ex = X509V3_EXT_conf_nid(nullptr, &ctx, nid, const_cast<char*>(value));
- if (!ex)
+ if (ex == nullptr)
{
BMCWEB_LOG_ERROR << "Error: In X509V3_EXT_conf_nidn: " << value;
return -1;
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 2a0353b..6b7d9e7 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -42,7 +42,7 @@
// boost::process::child::terminate uses SIGKILL, need to send SIGTERM
// to allow the proxy to stop nbd-client and the USB device gadget.
int rc = kill(proxy.id(), SIGTERM);
- if (rc)
+ if (rc != 0)
{
return;
}