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/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index df7279e..232f51c 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -1142,7 +1142,7 @@
[dbusObjectPath, username, password(std::move(password)),
roleId(std::move(roleId)), enabled, locked,
asyncResp{std::move(asyncResp)}](int rc) {
- if (!rc)
+ if (rc <= 0)
{
messages::resourceNotFound(
asyncResp->res, "#ManagerAccount.v1_4_0.ManagerAccount",
@@ -1727,7 +1727,8 @@
const std::pair<sdbusplus::message::object_path,
dbus::utility::DBusInteracesMap>&
user) {
- return !accountName.compare(user.first.filename());
+ return accountName.compare(user.first.filename()) ==
+ 0;
});
if (userIt == users.end())
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 23e3ead..4adaf0b 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -154,7 +154,7 @@
'e', 'r', 't', 's', '.', 'X',
'X', 'X', 'X', 'X', 'X', '\0'};
char* tempDirectory = mkdtemp(dirTemplate.data());
- if (tempDirectory)
+ if (tempDirectory != nullptr)
{
certDirectory = tempDirectory;
certificateFile = certDirectory / "cert.pem";
@@ -596,7 +596,7 @@
asyncResp->res.jsonValue["CertificateString"] = "";
const std::string* value =
std::get_if<std::string>(&property.second);
- if (value)
+ if (value != nullptr)
{
asyncResp->res.jsonValue["CertificateString"] = *value;
}
@@ -608,7 +608,7 @@
keyUsage = nlohmann::json::array();
const std::vector<std::string>* value =
std::get_if<std::vector<std::string>>(&property.second);
- if (value)
+ if (value != nullptr)
{
for (const std::string& usage : *value)
{
@@ -620,7 +620,7 @@
{
const std::string* value =
std::get_if<std::string>(&property.second);
- if (value)
+ if (value != nullptr)
{
updateCertIssuerOrSubject(
asyncResp->res.jsonValue["Issuer"], *value);
@@ -630,7 +630,7 @@
{
const std::string* value =
std::get_if<std::string>(&property.second);
- if (value)
+ if (value != nullptr)
{
updateCertIssuerOrSubject(
asyncResp->res.jsonValue["Subject"], *value);
@@ -640,7 +640,7 @@
{
const uint64_t* value =
std::get_if<uint64_t>(&property.second);
- if (value)
+ if (value != nullptr)
{
asyncResp->res.jsonValue["ValidNotAfter"] =
crow::utility::getDateTimeUint(*value);
@@ -650,7 +650,7 @@
{
const uint64_t* value =
std::get_if<uint64_t>(&property.second);
- if (value)
+ if (value != nullptr)
{
asyncResp->res.jsonValue["ValidNotBefore"] =
crow::utility::getDateTimeUint(*value);
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 5283fff..9b1aa43 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -685,7 +685,7 @@
// Count bits
for (long bitIdx = 7; bitIdx >= 0; bitIdx--)
{
- if (value & (1L << bitIdx))
+ if ((value & (1L << bitIdx)) != 0)
{
if (firstZeroInByteHit)
{
@@ -2355,7 +2355,7 @@
return;
}
// Need both vlanId and vlanEnable to service this request
- if (!vlanId)
+ if (vlanId == 0u)
{
messages::propertyMissing(asyncResp->res, "VLANId");
}
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp
index 6088758..9ce2f05 100644
--- a/redfish-core/lib/event_service.hpp
+++ b/redfish-core/lib/event_service.hpp
@@ -359,7 +359,7 @@
if (value == nullptr)
{
messages::propertyValueFormatError(
- asyncResp->res, item.value().dump(2, true),
+ asyncResp->res, item.value().dump(2, 1),
"HttpHeaders/" + item.key());
return;
}
@@ -432,7 +432,8 @@
registry.begin(), registry.end(),
[&id](const redfish::message_registries::
MessageEntry& messageEntry) {
- return !id.compare(messageEntry.first);
+ return id.compare(messageEntry.first) ==
+ 0;
}))
{
validId = true;
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 84e6b34..b2c5d4c 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -65,7 +65,7 @@
std::span<const MessageEntry>::iterator messageIt = std::find_if(
registry.begin(), registry.end(),
[&messageKey](const MessageEntry& messageEntry) {
- return !std::strcmp(messageEntry.first, messageKey.c_str());
+ return std::strcmp(messageEntry.first, messageKey.c_str()) == 0;
});
if (messageIt != registry.end())
{
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index c69af7e..549ab2d 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -500,7 +500,7 @@
{
values = ptr;
}
- if (keys && values)
+ if (keys != nullptr && values != nullptr)
{
if (keys->size() != values->size())
{
@@ -913,7 +913,7 @@
return CreatePIDRet::fail;
}
if (chassis.empty() &&
- !findChassis(managedObj, zonesStr[0], chassis))
+ findChassis(managedObj, zonesStr[0], chassis) == nullptr)
{
BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
messages::invalidObject(response->res, it.key());
@@ -1078,7 +1078,7 @@
return CreatePIDRet::fail;
}
if (chassis.empty() &&
- !findChassis(managedObj, zonesStrs[0], chassis))
+ findChassis(managedObj, zonesStrs[0], chassis) == nullptr)
{
BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
messages::invalidObject(response->res, it.key());
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 541e631..4ac4c77 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -66,8 +66,9 @@
interval = std::get_if<uint64_t>(&var);
}
}
- if (!emitsReadingsUpdate || !logToMetricReportsCollection ||
- !readingParams || !reportingType || !interval)
+ if (emitsReadingsUpdate == nullptr ||
+ logToMetricReportsCollection == nullptr || readingParams == nullptr ||
+ reportingType == nullptr || interval == nullptr)
{
BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
messages::internalError(asyncResp->res);
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index ad3ca8e..48f22b7 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -172,8 +172,8 @@
std::string interfaceChassisName =
chassis.substr(lastPos + 1, len);
- if (!interfaceChassisName.compare(
- sensorAsyncResp->chassisId))
+ if (interfaceChassisName.compare(
+ sensorAsyncResp->chassisId) == 0)
{
found = true;
break;
@@ -231,17 +231,17 @@
dbus::utility::DbusVariantType>&
property : properties)
{
- if (!property.first.compare("Scale"))
+ if (property.first.compare("Scale") == 0)
{
const int64_t* i =
std::get_if<int64_t>(&property.second);
- if (i)
+ if (i != nullptr)
{
scale = *i;
}
}
- else if (!property.first.compare("PowerCap"))
+ else if (property.first.compare("PowerCap") == 0)
{
const double* d =
std::get_if<double>(&property.second);
@@ -250,25 +250,26 @@
const uint32_t* u =
std::get_if<uint32_t>(&property.second);
- if (d)
+ if (d != nullptr)
{
powerCap = *d;
}
- else if (i)
+ else if (i != nullptr)
{
powerCap = static_cast<double>(*i);
}
- else if (u)
+ else if (u != nullptr)
{
powerCap = *u;
}
}
- else if (!property.first.compare("PowerCapEnable"))
+ else if (property.first.compare("PowerCapEnable") ==
+ 0)
{
const bool* b =
std::get_if<bool>(&property.second);
- if (b)
+ if (b != nullptr)
{
enabled = *b;
}
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 4d4b4cc..a53c112 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -965,7 +965,7 @@
std::string sensorNameLower =
boost::algorithm::to_lower_copy(sensorName);
- if (!sensorName.compare("total_power"))
+ if (sensorName.compare("total_power") == 0)
{
sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl";
// Put multiple "sensors" into a single PowerControl, so have
@@ -2551,7 +2551,7 @@
}
else if (sensorType == "power")
{
- if (!sensorName.compare("total_power"))
+ if (sensorName.compare("total_power") == 0)
{
fieldName = "PowerControl";
}
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index d680537..62bd11b 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -176,7 +176,7 @@
const uint16_t* coreCountVal =
std::get_if<uint16_t>(&property.second);
- if (!coreCountVal)
+ if (coreCountVal == nullptr)
{
messages::internalError(aResp->res);
return;
@@ -1574,7 +1574,8 @@
// Source target specified
BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource;
// Figure out which DBUS interface and property to use
- if (assignBootParameters(aResp, *bootSource, bootSourceStr, bootModeStr))
+ if (assignBootParameters(aResp, *bootSource, bootSourceStr, bootModeStr) !=
+ 0)
{
BMCWEB_LOG_DEBUG
<< "Invalid property value for BootSourceOverrideTarget: "
@@ -2238,7 +2239,7 @@
{
const bool* state = std::get_if<bool>(&property.second);
- if (!state)
+ if (state == nullptr)
{
messages::internalError(aResp->res);
return;
@@ -2250,7 +2251,7 @@
{
const std::string* s =
std::get_if<std::string>(&property.second);
- if (!s)
+ if (s == nullptr)
{
messages::internalError(aResp->res);
return;
@@ -2353,7 +2354,7 @@
if (property.first == "Enabled")
{
const bool* state = std::get_if<bool>(&property.second);
- if (!state)
+ if (state == nullptr)
{
return false;
}
@@ -2362,7 +2363,7 @@
else if (property.first == "EnterUtilizationPercent")
{
const uint8_t* util = std::get_if<uint8_t>(&property.second);
- if (!util)
+ if (util == nullptr)
{
return false;
}
@@ -2373,7 +2374,7 @@
// Convert Dbus time from milliseconds to seconds
const uint64_t* timeMilliseconds =
std::get_if<uint64_t>(&property.second);
- if (!timeMilliseconds)
+ if (timeMilliseconds == nullptr)
{
return false;
}
@@ -2386,7 +2387,7 @@
else if (property.first == "ExitUtilizationPercent")
{
const uint8_t* util = std::get_if<uint8_t>(&property.second);
- if (!util)
+ if (util == nullptr)
{
return false;
}
@@ -2397,7 +2398,7 @@
// Convert Dbus time from milliseconds to seconds
const uint64_t* timeMilliseconds =
std::get_if<uint64_t>(&property.second);
- if (!timeMilliseconds)
+ if (timeMilliseconds == nullptr)
{
return false;
}
diff --git a/redfish-core/lib/telemetry_service.hpp b/redfish-core/lib/telemetry_service.hpp
index 5457530..421985a 100644
--- a/redfish-core/lib/telemetry_service.hpp
+++ b/redfish-core/lib/telemetry_service.hpp
@@ -58,7 +58,7 @@
minInterval = std::get_if<uint64_t>(&var);
}
}
- if (!maxReports || !minInterval)
+ if (maxReports == nullptr || minInterval == nullptr)
{
BMCWEB_LOG_ERROR
<< "Property type mismatch or property is missing";
diff --git a/redfish-core/lib/trigger.hpp b/redfish-core/lib/trigger.hpp
index bb0a0e2..cdd5781 100644
--- a/redfish-core/lib/trigger.hpp
+++ b/redfish-core/lib/trigger.hpp
@@ -80,7 +80,7 @@
const std::vector<DiscreteThresholdParams>* discreteParams =
std::get_if<std::vector<DiscreteThresholdParams>>(&thresholdParams);
- if (!discreteParams)
+ if (discreteParams == nullptr)
{
return std::nullopt;
}
@@ -113,7 +113,7 @@
const std::vector<NumericThresholdParams>* numericParams =
std::get_if<std::vector<NumericThresholdParams>>(&thresholdParams);
- if (!numericParams)
+ if (numericParams == nullptr)
{
return std::nullopt;
}
@@ -204,7 +204,8 @@
}
}
- if (!name || !discrete || !sensors || !reports || !actions || !thresholds)
+ if (name == nullptr || discrete == nullptr || sensors == nullptr ||
+ reports == nullptr || actions == nullptr || thresholds == nullptr)
{
BMCWEB_LOG_ERROR
<< "Property type mismatch or property is missing in Trigger: "
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index ab27fc7..9e44e80 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -111,7 +111,7 @@
if (property == "WriteProtected")
{
const bool* writeProtectedValue = std::get_if<bool>(&value);
- if (writeProtectedValue)
+ if (writeProtectedValue != nullptr)
{
aResp->res.jsonValue["WriteProtected"] =
*writeProtectedValue;
@@ -126,7 +126,7 @@
if (property == "Active")
{
const bool* activeValue = std::get_if<bool>(&value);
- if (!activeValue)
+ if (activeValue == nullptr)
{
BMCWEB_LOG_DEBUG << "Value Active not found";
return;
@@ -578,7 +578,7 @@
SecureBuffer pack(FormatterFunc formatter)
{
SecureBuffer packed{new Buffer{}};
- if (formatter)
+ if (formatter != nullptr)
{
formatter(credentials.user(), credentials.password(), *packed);
}