diff options
author | Ed Tanous <edtanous@google.com> | 2022-01-25 21:39:19 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-15 03:35:55 +0300 |
commit | e662eae819f545ef07193f216b42e161b7ff7a46 (patch) | |
tree | 2b13d88ae009fa7af3396252c8787992ff2cc6c8 | |
parent | c5ba4c27ddb28c7844c0ea3078df4114f531dd25 (diff) | |
download | bmcweb-e662eae819f545ef07193f216b42e161b7ff7a46.tar.xz |
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
26 files changed, 109 insertions, 99 deletions
diff --git a/.clang-tidy b/.clang-tidy index 00276808ff..9958891b15 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -275,6 +275,7 @@ readability-container-size-empty, readability-delete-null-pointer, readability-deleted-default, readability-else-after-return, +readability-implicit-bool-conversion, readability-named-parameter, readability-redundant-control-flow, readability-redundant-declaration, diff --git a/http/routing.hpp b/http/routing.hpp index 9032b148e2..8fd45589fc 100644 --- a/http/routing.hpp +++ b/http/routing.hpp @@ -673,9 +673,10 @@ class Trie bool isSimpleNode() const { - return !ruleIndex && std::all_of(std::begin(paramChildrens), - std::end(paramChildrens), - [](size_t x) { return !x; }); + return ruleIndex == 0 && + std::all_of(std::begin(paramChildrens), + std::end(paramChildrens), + [](size_t x) { return x == 0U; }); } }; @@ -687,7 +688,7 @@ class Trie { for (size_t x : node->paramChildrens) { - if (!x) + if (x == 0u) { continue; } @@ -801,14 +802,14 @@ class Trie auto updateFound = [&found, &matchParams](std::pair<unsigned, RoutingParams>& ret) { - if (ret.first && (!found || found > ret.first)) + if (ret.first != 0U && (found == 0U || found > ret.first)) { found = ret.first; matchParams = std::move(ret.second); } }; - if (node->paramChildrens[static_cast<size_t>(ParamType::INT)]) + if (node->paramChildrens[static_cast<size_t>(ParamType::INT)] != 0U) { char c = reqUrl[pos]; if ((c >= '0' && c <= '9') || c == '+' || c == '-') @@ -831,7 +832,7 @@ class Trie } } - if (node->paramChildrens[static_cast<size_t>(ParamType::UINT)]) + if (node->paramChildrens[static_cast<size_t>(ParamType::UINT)] != 0U) { char c = reqUrl[pos]; if ((c >= '0' && c <= '9') || c == '+') @@ -854,7 +855,7 @@ class Trie } } - if (node->paramChildrens[static_cast<size_t>(ParamType::DOUBLE)]) + if (node->paramChildrens[static_cast<size_t>(ParamType::DOUBLE)] != 0U) { char c = reqUrl[pos]; if ((c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.') @@ -876,7 +877,7 @@ class Trie } } - if (node->paramChildrens[static_cast<size_t>(ParamType::STRING)]) + if (node->paramChildrens[static_cast<size_t>(ParamType::STRING)] != 0U) { size_t epos = pos; for (; epos < reqUrl.size(); epos++) @@ -901,7 +902,7 @@ class Trie } } - if (node->paramChildrens[static_cast<size_t>(ParamType::PATH)]) + if (node->paramChildrens[static_cast<size_t>(ParamType::PATH)] != 0U) { size_t epos = reqUrl.size(); @@ -960,7 +961,7 @@ class Trie if (url.compare(i, x.second.size(), x.second) == 0) { size_t index = static_cast<size_t>(x.first); - if (!nodes[idx].paramChildrens[index]) + if (nodes[idx].paramChildrens[index] == 0U) { unsigned newNodeIdx = newNode(); nodes[idx].paramChildrens[index] = newNodeIdx; @@ -976,7 +977,7 @@ class Trie else { std::string piece(&c, 1); - if (!nodes[idx].children.count(piece)) + if (nodes[idx].children.count(piece) == 0U) { unsigned newNodeIdx = newNode(); nodes[idx].children.emplace(piece, newNodeIdx); @@ -984,7 +985,7 @@ class Trie idx = nodes[idx].children[piece]; } } - if (nodes[idx].ruleIndex) + if (nodes[idx].ruleIndex != 0U) { throw std::runtime_error("handler already exists for " + url); } @@ -996,7 +997,7 @@ class Trie { for (size_t i = 0; i < static_cast<size_t>(ParamType::MAX); i++) { - if (n->paramChildrens[i]) + if (n->paramChildrens[i] != 0U) { BMCWEB_LOG_DEBUG << std::string( 2U * level, ' ') /*<< "("<<n->paramChildrens[i]<<") "*/; @@ -1097,7 +1098,7 @@ class Router for (size_t method = 0, methodBit = 1; method < maxHttpVerbCount; method++, methodBit <<= 1) { - if (ruleObject->methodsBitfield & methodBit) + if ((ruleObject->methodsBitfield & methodBit) > 0U) { perMethods[method].rules.emplace_back(ruleObject); perMethods[method].trie.add( @@ -1153,7 +1154,7 @@ class Router const std::pair<unsigned, RoutingParams>& found = trie.find(req.url); unsigned ruleIndex = found.first; - if (!ruleIndex) + if (ruleIndex == 0U) { BMCWEB_LOG_DEBUG << "Cannot match rules " << req.url; res.result(boost::beast::http::status::not_found); @@ -1246,7 +1247,7 @@ class Router unsigned ruleIndex = found.first; - if (!ruleIndex) + if (ruleIndex == 0U) { // Check to see if this url exists at any verb for (const PerMethod& p : perMethods) diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp index 9bc79ad962..8519b5a400 100644 --- a/include/dbus_monitor.hpp +++ b/include/dbus_monitor.hpp @@ -31,7 +31,7 @@ static boost::container::flat_map<crow::websocket::Connection*, 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 30186b650e..73c315fb73 100644 --- a/include/hostname_monitor.hpp +++ b/include/hostname_monitor.hpp @@ -35,7 +35,7 @@ inline void installCertificate(const std::filesystem::path& certPath) 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 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */, 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 740e2187ce..3970992974 100644 --- a/include/http_utility.hpp +++ b/include/http_utility.hpp @@ -53,7 +53,7 @@ inline std::string urlEncode(const std::string_view value) 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 b39bada519..7dccbd8e20 100644 --- a/include/ibm/locks.hpp +++ b/include/ibm/locks.hpp @@ -279,7 +279,7 @@ inline void Lock::releaseLock(const ListOfTransactionIds& refRids) { 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 6861571073..b457935e84 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -656,16 +656,16 @@ inline int convertJsonToDbus(sd_bus_message* m, const std::string& argType, 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 @@ inline int readArrayFromMessage(const std::string& typeCode, 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 @@ inline void findActionOnInterface( transaction->methodFailed = true; const sd_bus_error* e = m2.get_error(); - if (e) + if (e != nullptr) { setErrorResponse( transaction->res, @@ -2002,10 +2002,12 @@ inline void handlePut(const crow::Request& req, 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 966fbdf59c..828a44c2a5 100644 --- a/include/security_headers.hpp +++ b/include/security_headers.hpp @@ -25,7 +25,7 @@ inline void addSecurityHeaders(const crow::Request& req [[maybe_unused]], "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 fcb79f24f6..30145f8136 100644 --- a/include/ssl_key_handler.hpp +++ b/include/ssl_key_handler.hpp @@ -40,7 +40,7 @@ inline bool validateCertificate(X509* const cert) { // 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 @@ inline bool validateCertificate(X509* const cert) // 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 @@ inline bool verifyOpensslKeyCert(const std::string& filepath) 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 bool verifyOpensslKeyCert(const std::string& filepath) 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 @@ inline X509* loadCert(const std::string& filePath) } 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 @@ inline X509* loadCert(const std::string& filePath) 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 @@ inline int addExt(X509* cert, int nid, const char* value) // 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 2a0353be32..6b7d9e7a9f 100644 --- a/include/vm_websocket.hpp +++ b/include/vm_websocket.hpp @@ -42,7 +42,7 @@ class Handler : public std::enable_shared_from_this<Handler> // 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; } diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 55485c63e8..051e49506e 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -95,7 +95,7 @@ static const Message* std::span<const MessageEntry>::iterator messageIt = std::find_if(registry.begin(), registry.end(), [&messageKey](const MessageEntry& messageEntry) { - return !messageKey.compare(messageEntry.first); + return messageKey.compare(messageEntry.first) == 0; }); if (messageIt != registry.end()) { @@ -708,7 +708,7 @@ class EventServiceManager std::string id; int retry = 3; - while (retry) + while (retry != 0) { id = std::to_string(dist(gen)); if (gen.error()) @@ -764,7 +764,7 @@ class EventServiceManager if (serviceEnabled != cfg.enabled) { serviceEnabled = cfg.enabled; - if (serviceEnabled && noOfMetricReportSubscribers) + if (serviceEnabled && noOfMetricReportSubscribers != 0U) { registerMetricReportSignal(); } @@ -827,7 +827,7 @@ class EventServiceManager if (noOfMetricReportSubscribers != metricReportSubCount) { noOfMetricReportSubscribers = metricReportSubCount; - if (noOfMetricReportSubscribers) + if (noOfMetricReportSubscribers != 0U) { registerMetricReportSignal(); } @@ -860,7 +860,7 @@ class EventServiceManager std::string id; int retry = 3; - while (retry) + while (retry != 0) { id = std::to_string(dist(gen)); if (gen.error()) @@ -989,7 +989,7 @@ class EventServiceManager void sendEvent(const nlohmann::json& eventMessageIn, const std::string& origin, const std::string& resType) { - if (!serviceEnabled || !noOfEventLogSubscribers) + if (!serviceEnabled || (noOfEventLogSubscribers == 0u)) { BMCWEB_LOG_DEBUG << "EventService disabled or no Subscriptions."; return; @@ -1122,7 +1122,7 @@ class EventServiceManager continue; } - if (!serviceEnabled || !noOfEventLogSubscribers) + if (!serviceEnabled || noOfEventLogSubscribers == 0) { // If Service is not enabled, no need to compute // the remaining items below. @@ -1153,7 +1153,7 @@ class EventServiceManager messageKey, messageArgs); } - if (!serviceEnabled || !noOfEventLogSubscribers) + if (!serviceEnabled || noOfEventLogSubscribers == 0) { BMCWEB_LOG_DEBUG << "EventService disabled or no Subscriptions."; return; @@ -1340,7 +1340,7 @@ class EventServiceManager const telemetry::TimestampReadings* readings = std::get_if<telemetry::TimestampReadings>(&found->second); - if (!readings) + if (readings == nullptr) { BMCWEB_LOG_INFO << "Failed to get Readings from Report properties"; return; diff --git a/redfish-core/include/gzfile.hpp b/redfish-core/include/gzfile.hpp index 2001756a74..567741dfd8 100644 --- a/redfish-core/include/gzfile.hpp +++ b/redfish-core/include/gzfile.hpp @@ -13,7 +13,7 @@ class GzFileReader std::vector<std::string>& logEntries, size_t& logCount) { gzFile logStream = gzopen(filename.c_str(), "r"); - if (!logStream) + if (logStream == nullptr) { BMCWEB_LOG_ERROR << "Can't open gz file: " << filename << '\n'; return false; @@ -71,7 +71,7 @@ class GzFileReader BMCWEB_LOG_ERROR << "Error occurs during parsing host log.\n"; return false; } - } while (!gzeof(logStream)); + } while (gzeof(logStream) != 1); return true; } diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index df7279e281..232f51c178 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -1142,7 +1142,7 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, [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 @@ inline void requestAccountServiceRoutes(App& app) 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 23e3eadceb..4adaf0b947 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -154,7 +154,7 @@ class CertificateFile '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 @@ static void getCertificateProperties( 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 @@ static void getCertificateProperties( 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 @@ static void getCertificateProperties( { 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 @@ static void getCertificateProperties( { 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 @@ static void getCertificateProperties( { 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 @@ static void getCertificateProperties( { 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 5283fff176..9b1aa438b5 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -685,7 +685,7 @@ inline bool ipv4VerifyIpAndGetBitcount(const std::string& ip, // Count bits for (long bitIdx = 7; bitIdx >= 0; bitIdx--) { - if (value & (1L << bitIdx)) + if ((value & (1L << bitIdx)) != 0) { if (firstZeroInByteHit) { @@ -2355,7 +2355,7 @@ inline void requestEthernetInterfacesRoutes(App& app) 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 6088758d2d..9ce2f05a91 100644 --- a/redfish-core/lib/event_service.hpp +++ b/redfish-core/lib/event_service.hpp @@ -359,7 +359,7 @@ inline void requestRoutesEventDestinationCollection(App& app) 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 @@ inline void requestRoutesEventDestinationCollection(App& app) 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 84e6b34c36..b2c5d4ca67 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -65,7 +65,7 @@ static const Message* 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 c69af7ece5..549ab2d7ad 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -500,7 +500,7 @@ inline void { values = ptr; } - if (keys && values) + if (keys != nullptr && values != nullptr) { if (keys->size() != values->size()) { @@ -913,7 +913,7 @@ inline CreatePIDRet createPidInterface( 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 @@ inline CreatePIDRet createPidInterface( 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 541e631ffa..4ac4c777c7 100644 --- a/redfish-core/lib/metric_report_definition.hpp +++ b/redfish-core/lib/metric_report_definition.hpp @@ -66,8 +66,9 @@ inline void fillReportDefinition( 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 ad3ca8ec12..48f22b7747 100644 --- a/redfish-core/lib/power.hpp +++ b/redfish-core/lib/power.hpp @@ -172,8 +172,8 @@ inline void requestRoutesPower(App& app) 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 @@ inline void requestRoutesPower(App& app) 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 @@ inline void requestRoutesPower(App& app) 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 4d4b4cce27..a53c1124fa 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -965,7 +965,7 @@ inline void objectInterfacesToJson( 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 @@ inline void getSensorData( } 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 d6805374d3..62bd11b097 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -176,7 +176,7 @@ inline void getProcessorProperties( 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 @@ inline void setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, // 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 @@ inline void { const bool* state = std::get_if<bool>(&property.second); - if (!state) + if (state == nullptr) { messages::internalError(aResp->res); return; @@ -2250,7 +2251,7 @@ inline void { 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 @@ inline bool parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, if (property.first == "Enabled") { const bool* state = std::get_if<bool>(&property.second); - if (!state) + if (state == nullptr) { return false; } @@ -2362,7 +2363,7 @@ inline bool parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 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 @@ inline bool parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, // 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 @@ inline bool parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 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 @@ inline bool parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, // 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 5457530fbd..421985a64f 100644 --- a/redfish-core/lib/telemetry_service.hpp +++ b/redfish-core/lib/telemetry_service.hpp @@ -58,7 +58,7 @@ inline void handleTelemetryServiceGet( 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 bb0a0e2ac3..cdd5781b99 100644 --- a/redfish-core/lib/trigger.hpp +++ b/redfish-core/lib/trigger.hpp @@ -80,7 +80,7 @@ inline std::optional<nlohmann::json> const std::vector<DiscreteThresholdParams>* discreteParams = std::get_if<std::vector<DiscreteThresholdParams>>(&thresholdParams); - if (!discreteParams) + if (discreteParams == nullptr) { return std::nullopt; } @@ -113,7 +113,7 @@ inline std::optional<nlohmann::json> const std::vector<NumericThresholdParams>* numericParams = std::get_if<std::vector<NumericThresholdParams>>(&thresholdParams); - if (!numericParams) + if (numericParams == nullptr) { return std::nullopt; } @@ -204,7 +204,8 @@ inline bool fillTrigger( } } - 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 ab27fc7b8a..9e44e80a7a 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -111,7 +111,7 @@ inline void 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 @@ inline void 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 @@ class CredentialsProvider SecureBuffer pack(FormatterFunc formatter) { SecureBuffer packed{new Buffer{}}; - if (formatter) + if (formatter != nullptr) { formatter(credentials.user(), credentials.password(), *packed); } diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp index b613008360..b05161d316 100644 --- a/src/webserver_main.cpp +++ b/src/webserver_main.cpp @@ -40,7 +40,7 @@ inline void setupSocket(crow::App& app) { BMCWEB_LOG_INFO << "attempting systemd socket activation"; if (sd_is_socket_inet(SD_LISTEN_FDS_START, AF_UNSPEC, SOCK_STREAM, 1, - 0)) + 0) != 0) { BMCWEB_LOG_INFO << "Starting webserver on socket handle " << SD_LISTEN_FDS_START; @@ -113,7 +113,7 @@ int run() crow::google_api::requestRoutes(app); #endif - if (bmcwebInsecureDisableXssPrevention) + if (bmcwebInsecureDisableXssPrevention != 0) { cors_preflight::requestRoutes(app); } @@ -128,7 +128,7 @@ int run() #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES int rc = redfish::EventServiceManager::startEventLogMonitor(*io); - if (rc) + if (rc != 0) { BMCWEB_LOG_ERROR << "Redfish event handler setup failed..."; return rc; |