diff options
author | Ed Tanous <edtanous@google.com> | 2022-01-25 21:28:56 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-02-11 23:30:05 +0300 |
commit | e05aec50f10116e6dda7e377bc61799aa5b7c166 (patch) | |
tree | 964aedffefcc787029c571a83889247caa0d3968 | |
parent | 213ffc701d838bece5893cda23475e7518bd6955 (diff) | |
download | bmcweb-e05aec50f10116e6dda7e377bc61799aa5b7c166.tar.xz |
Add readability-redundant-* checks
There's a number of redundancies in our code that clang can sanitize
out. Fix the existing problems, and enable the checks.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ie63d7b7f0777b702fbf1b23a24e1bed7b4f5183b
-rw-r--r-- | .clang-tidy | 7 | ||||
-rw-r--r-- | http/app.hpp | 2 | ||||
-rw-r--r-- | http/http_connection.hpp | 3 | ||||
-rw-r--r-- | http/websocket.hpp | 2 | ||||
-rw-r--r-- | include/authorization.hpp | 2 | ||||
-rw-r--r-- | include/ibm/management_console_rest.hpp | 6 | ||||
-rw-r--r-- | include/login_routes.hpp | 2 | ||||
-rw-r--r-- | include/openbmc_dbus_rest.hpp | 2 | ||||
-rw-r--r-- | include/persistent_data.hpp | 2 | ||||
-rw-r--r-- | redfish-core/include/event_service_manager.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/account_service.hpp | 6 | ||||
-rw-r--r-- | redfish-core/lib/ethernet.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/hypervisor_system.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/memory.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/processor.hpp | 10 | ||||
-rw-r--r-- | redfish-core/lib/roles.hpp | 2 | ||||
-rw-r--r-- | redfish-core/lib/sensors.hpp | 16 | ||||
-rw-r--r-- | redfish-core/lib/systems.hpp | 8 | ||||
-rw-r--r-- | redfish-core/lib/update_service.hpp | 4 | ||||
-rw-r--r-- | redfish-core/lib/virtual_media.hpp | 6 | ||||
-rw-r--r-- | redfish-core/ut/configfile_test.cpp | 2 |
22 files changed, 48 insertions, 44 deletions
diff --git a/.clang-tidy b/.clang-tidy index 953c78e780..23cc7aea1f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -276,6 +276,13 @@ readability-deleted-default, readability-else-after-return, readability-named-parameter, readability-redundant-control-flow, +readability-redundant-declaration, +readability-redundant-function-ptr-dereference, +readability-redundant-member-init, +readability-redundant-preprocessor, +readability-redundant-smartptr-get, +readability-redundant-string-cstr, +readability-redundant-string-init, readability-identifier-naming' WarningsAsErrors: '*' diff --git a/http/app.hpp b/http/app.hpp index 03de3f8952..c1472e5ba3 100644 --- a/http/app.hpp +++ b/http/app.hpp @@ -142,7 +142,7 @@ class App std::vector<const std::string*> getRoutes() { - const std::string root(""); + const std::string root; return router.getRoutes(root); } std::vector<const std::string*> getRoutes(const std::string& parent) diff --git a/http/http_connection.hpp b/http/http_connection.hpp index 0b58e9b6f5..61d3f7b901 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -261,7 +261,7 @@ class Connection : return true; } sslUser.resize(lastChar); - std::string unsupportedClientId = ""; + std::string unsupportedClientId; sessionIsFromTransport = true; userSession = persistent_data::SessionStore::getInstance() .generateUserSession( @@ -725,7 +725,6 @@ class Connection : BMCWEB_LOG_DEBUG << this << " timer started"; } - private: Adaptor adaptor; Handler* handler; // Making this a std::optional allows it to be efficiently destroyed and diff --git a/http/websocket.hpp b/http/websocket.hpp index eadb276c0c..213c4c74c0 100644 --- a/http/websocket.hpp +++ b/http/websocket.hpp @@ -77,7 +77,7 @@ class ConnectionImpl : public Connection std::function<void(Connection&, const std::string&)> closeHandler, std::function<void(Connection&)> errorHandler) : Connection(reqIn, reqIn.session->username), - ws(std::move(adaptorIn)), inString(), inBuffer(inString, 131088), + ws(std::move(adaptorIn)), inBuffer(inString, 131088), openHandler(std::move(openHandler)), messageHandler(std::move(messageHandler)), closeHandler(std::move(closeHandler)), diff --git a/include/authorization.hpp b/include/authorization.hpp index 27d7b32e2b..f8e74b9af0 100644 --- a/include/authorization.hpp +++ b/include/authorization.hpp @@ -85,7 +85,7 @@ static std::shared_ptr<persistent_data::UserSession> // needed. // This whole flow needs to be revisited anyway, as we can't be // calling directly into pam for every request - std::string unsupportedClientId = ""; + std::string unsupportedClientId; return persistent_data::SessionStore::getInstance().generateUserSession( user, clientIp, unsupportedClientId, persistent_data::PersistenceType::SINGLE_REQUEST, isConfigureSelfOnly); diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index e80e727210..39146c91ad 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -512,7 +512,8 @@ inline void asyncResp->res.result(boost::beast::http::status::conflict); auto var = std::get<std::pair<uint32_t, LockRequest>>(conflictStatus.second); - nlohmann::json returnJson, segments; + nlohmann::json returnJson; + nlohmann::json segments; nlohmann::json myarray = nlohmann::json::array(); returnJson["TransactionID"] = var.first; returnJson["SessionID"] = std::get<0>(var.second); @@ -579,7 +580,8 @@ inline void asyncResp->res.result(boost::beast::http::status::unauthorized); auto var = statusRelease.second; - nlohmann::json returnJson, segments; + nlohmann::json returnJson; + nlohmann::json segments; nlohmann::json myArray = nlohmann::json::array(); returnJson["TransactionID"] = var.first; returnJson["SessionID"] = std::get<0>(var.second); diff --git a/include/login_routes.hpp b/include/login_routes.hpp index c918cddd1a..1087b0b8de 100644 --- a/include/login_routes.hpp +++ b/include/login_routes.hpp @@ -185,7 +185,7 @@ inline void requestRoutes(App& app) } else { - std::string unsupportedClientId = ""; + std::string unsupportedClientId; auto session = persistent_data::SessionStore::getInstance() .generateUserSession( diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 8aab757d48..6861571073 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -2044,7 +2044,7 @@ inline void handleDBusUrl(const crow::Request& req, // If accessing a single attribute, fill in and update objectPath, // otherwise leave destProperty blank - std::string destProperty = ""; + std::string destProperty; const char* attrSeperator = "/attr/"; size_t attrPosition = objectPath.find(attrSeperator); if (attrPosition != objectPath.npos) diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp index 47bb8a9f4c..02f2ccec11 100644 --- a/include/persistent_data.hpp +++ b/include/persistent_data.hpp @@ -289,7 +289,7 @@ class ConfigFile persistentFile << data; } - std::string systemUuid{""}; + std::string systemUuid; }; inline ConfigFile& getConfig() diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index ec294ae200..3429c022ae 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -1356,7 +1356,7 @@ class EventServiceManager for (const auto& it : EventServiceManager::getInstance().subscriptionsMap) { - Subscription& entry = *it.second.get(); + Subscription& entry = *it.second; if (entry.eventFormatType == metricReportFormatType) { entry.filterAndSendReports(id, *readings); diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index 87707825ea..5530e12ad0 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -1191,7 +1191,7 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, messages::success(asyncResp->res); return; }, - "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), + "xyz.openbmc_project.User.Manager", dbusObjectPath, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.Attributes", "UserEnabled", dbus::utility::DbusVariantType{*enabled}); @@ -1221,7 +1221,7 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, } messages::success(asyncResp->res); }, - "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), + "xyz.openbmc_project.User.Manager", dbusObjectPath, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.Attributes", "UserPrivilege", dbus::utility::DbusVariantType{priv}); @@ -1250,7 +1250,7 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, messages::success(asyncResp->res); return; }, - "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), + "xyz.openbmc_project.User.Manager", dbusObjectPath, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.Attributes", "UserLockedForFailedAttempt", diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index f4260a8217..5283fff176 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -2188,7 +2188,7 @@ inline void requestEthernetInterfacesRoutes(App& app) } }; - if (vlanEnable == true) + if (vlanEnable) { crow::connections::systemBus->async_method_call( std::move(callback), diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index 588cf13ffb..645e39f6b7 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -541,7 +541,7 @@ inline void setDHCPEnabled(const std::string& ifaceId, // Set the IPv4 address origin to the DHCP / Static as per the new value // of the DHCPEnabled property std::string origin; - if (ipv4DHCPEnabled == false) + if (!ipv4DHCPEnabled) { origin = "xyz.openbmc_project.Network.IP.AddressOrigin.Static"; } diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index aa4d5ec49e..84e6b34c36 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -676,7 +676,7 @@ inline void entryID + "/attachment"; } } - if (foundDumpEntry == false) + if (!foundDumpEntry) { BMCWEB_LOG_ERROR << "Can't find Dump Entry"; messages::internalError(asyncResp->res); diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp index 49304e2150..f20681b61c 100644 --- a/redfish-core/lib/memory.hpp +++ b/redfish-core/lib/memory.hpp @@ -546,7 +546,7 @@ inline void getDimmDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, << "Invalid property type for Dimm Presence"; return; } - if (*value == false) + if (!*value) { aResp->res.jsonValue["Status"]["State"] = "Absent"; } diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp index 8e078816d9..b51a901566 100644 --- a/redfish-core/lib/processor.hpp +++ b/redfish-core/lib/processor.hpp @@ -92,7 +92,7 @@ inline void getCpuDataByInterface( messages::internalError(aResp->res); return; } - if (*cpuPresent == false) + if (!*cpuPresent) { // Slot is not populated aResp->res.jsonValue["Status"]["State"] = "Absent"; @@ -106,7 +106,7 @@ inline void getCpuDataByInterface( messages::internalError(aResp->res); return; } - if (*cpuFunctional == false) + if (!*cpuFunctional) { aResp->res.jsonValue["Status"]["Health"] = "Critical"; } @@ -248,7 +248,7 @@ inline void getCpuDataByService(std::shared_ptr<bmcweb::AsyncResp> aResp, std::get_if<bool>(&property.second); if (present != nullptr) { - if (*present == true) + if (*present) { slotPresent = true; totalCores++; @@ -442,12 +442,12 @@ inline void getAcceleratorDataByService( std::string state = "Enabled"; std::string health = "OK"; - if (accPresent != nullptr && *accPresent == false) + if (accPresent != nullptr && !*accPresent) { state = "Absent"; } - if ((accFunctional != nullptr) && (*accFunctional == false)) + if ((accFunctional != nullptr) && !*accFunctional) { if (state == "Enabled") { diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp index c18942f5b0..6c67a33f81 100644 --- a/redfish-core/lib/roles.hpp +++ b/redfish-core/lib/roles.hpp @@ -81,7 +81,7 @@ inline void requestRoutesRoles(App& app) const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& roleId) { nlohmann::json privArray = nlohmann::json::array(); - if (false == getAssignedPrivFromRole(roleId, privArray)) + if (!getAssignedPrivFromRole(roleId, privArray)) { messages::resourceNotFound(asyncResp->res, "Role", roleId); diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index f3fa52c6fe..4d4b4cce27 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -284,11 +284,7 @@ enum class LedState class InventoryItem { public: - InventoryItem(const std::string& objPath) : - objectPath(objPath), name(), isPresent(true), isFunctional(true), - isPowerSupply(false), powerSupplyEfficiencyPercent(-1), manufacturer(), - model(), partNumber(), serialNumber(), sensors(), ledObjectPath(""), - ledState(LedState::UNKNOWN) + InventoryItem(const std::string& objPath) : objectPath(objPath) { // Set inventory item name to last node of object path sdbusplus::message::object_path path(objectPath); @@ -301,17 +297,17 @@ class InventoryItem std::string objectPath; std::string name; - bool isPresent; - bool isFunctional; - bool isPowerSupply; - int powerSupplyEfficiencyPercent; + bool isPresent = true; + bool isFunctional = true; + bool isPowerSupply = false; + int powerSupplyEfficiencyPercent = -1; std::string manufacturer; std::string model; std::string partNumber; std::string serialNumber; std::set<std::string> sensors; std::string ledObjectPath; - LedState ledState; + LedState ledState = LedState::UNKNOWN; }; /** diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 4cc3d8b743..d6805374d3 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -55,7 +55,7 @@ inline void aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; if (prevMemSummary == "Disabled") { - if (isDimmFunctional == true) + if (isDimmFunctional) { aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = "Enabled"; @@ -114,7 +114,7 @@ inline void // Functional. if (prevProcState == "Disabled") { - if (isCpuFunctional == true) + if (isCpuFunctional) { aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Enabled"; @@ -1129,7 +1129,7 @@ inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) } BMCWEB_LOG_DEBUG << "Auto Reboot: " << autoRebootEnabled; - if (autoRebootEnabled == true) + if (autoRebootEnabled) { aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = "RetryAttempts"; @@ -2490,7 +2490,7 @@ inline void getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp) return; } - if (parseIpsProperties(aResp, properties) == false) + if (!parseIpsProperties(aResp, properties)) { messages::internalError(aResp->res); return; diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index ba92748b3c..4b1852094f 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -263,7 +263,7 @@ static void monitorForSoftwareAvailable( int timeoutTimeSeconds = 10) { // Only allow one FW update at a time - if (fwUpdateInProgress != false) + if (fwUpdateInProgress) { if (asyncResp) { @@ -819,7 +819,7 @@ inline void requestRoutesSoftwareInventory(App& app) std::string, std::vector<std::string>>>>& obj : subtree) { - if (boost::ends_with(obj.first, *swId) != true) + if (!boost::ends_with(obj.first, *swId)) { continue; } diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp index d646698ad1..ab27fc7b8a 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -133,7 +133,7 @@ inline void } aResp->res.jsonValue["Inserted"] = *activeValue; - if (*activeValue == true) + if (*activeValue) { aResp->res.jsonValue["ConnectedVia"] = "Applet"; } @@ -400,7 +400,7 @@ inline bool } // optional param inserted must be true - if ((inserted != std::nullopt) && (*inserted != true)) + if ((inserted != std::nullopt) && !*inserted) { BMCWEB_LOG_ERROR << "Request action optional parameter Inserted must be true."; @@ -814,7 +814,7 @@ inline void requestNBDVirtualMediaRoutes(App& app) actionParams.inserted, actionParams.transferMethod, actionParams.transferProtocolType); - if (paramsValid == false) + if (!paramsValid) { return; } diff --git a/redfish-core/ut/configfile_test.cpp b/redfish-core/ut/configfile_test.cpp index 9f6bc13599..7e9c7855bf 100644 --- a/redfish-core/ut/configfile_test.cpp +++ b/redfish-core/ut/configfile_test.cpp @@ -49,7 +49,7 @@ TEST(ConfigFileTest, FileNameNull) { crow::Response res; - const std::string fileName = ""; + const std::string fileName; EXPECT_FALSE(isValidConfigFileName(fileName, res)); } TEST(ConfigFileTest, FileNameSlash) |