Fix some warnings by cppcheck
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Icee0abe2e3130aa225db776efdcd47200eb38f8d
diff --git a/fault-monitor/fru-fault-monitor.cpp b/fault-monitor/fru-fault-monitor.cpp
index d59aa16..fb4f891 100644
--- a/fault-monitor/fru-fault-monitor.cpp
+++ b/fault-monitor/fru-fault-monitor.cpp
@@ -78,6 +78,7 @@
elog<ObjectNotFoundErr>(ObjectNotFoundError::METHOD_NAME("GetObject"),
ObjectNotFoundError::PATH(path.c_str()),
ObjectNotFoundError::INTERFACE(OBJMGR_IFACE));
+ return {};
}
return mapperResponse.cbegin()->first;
diff --git a/fault-monitor/fru-fault-monitor.hpp b/fault-monitor/fru-fault-monitor.hpp
index 5658218..923a0f9 100644
--- a/fault-monitor/fru-fault-monitor.hpp
+++ b/fault-monitor/fru-fault-monitor.hpp
@@ -45,7 +45,7 @@
/** @brief constructs Add a watch for FRU faults.
* @param[in] bus - The Dbus bus object
*/
- Add(sdbusplus::bus::bus& bus) :
+ explicit Add(sdbusplus::bus::bus& bus) :
matchCreated(
bus,
sdbusplus::bus::match::rules::interfacesAdded() +
diff --git a/fault-monitor/operational-status-monitor.cpp b/fault-monitor/operational-status-monitor.cpp
index ffed55f..de6ee21 100644
--- a/fault-monitor/operational-status-monitor.cpp
+++ b/fault-monitor/operational-status-monitor.cpp
@@ -81,9 +81,7 @@
return {};
}
- auto& endpoints = std::get<std::vector<std::string>>(endpoint);
-
- return endpoints;
+ return std::get<std::vector<std::string>>(endpoint);
}
void Monitor::updateAssertedProperty(
diff --git a/fault-monitor/operational-status-monitor.hpp b/fault-monitor/operational-status-monitor.hpp
index ccf65a5..3fa995d 100644
--- a/fault-monitor/operational-status-monitor.hpp
+++ b/fault-monitor/operational-status-monitor.hpp
@@ -39,7 +39,7 @@
*
* @param[in] bus - D-Bus object
*/
- Monitor(sdbusplus::bus::bus& bus) :
+ explicit Monitor(sdbusplus::bus::bus& bus) :
bus(bus),
matchSignal(bus,
"type='signal',member='PropertiesChanged', "
diff --git a/lamptest.cpp b/lamptest.cpp
index 4c58e80..cd87bc2 100644
--- a/lamptest.cpp
+++ b/lamptest.cpp
@@ -2,6 +2,8 @@
#include <phosphor-logging/lg2.hpp>
+#include <algorithm>
+
namespace phosphor
{
namespace led
@@ -276,16 +278,12 @@
// define the default JSON as empty
const std::vector<std::string> empty{};
auto forceLEDs = json.value("forceLEDs", empty);
- for (auto& member : forceLEDs)
- {
- forceUpdateLEDs.push_back(PHY_LED_PATH + member);
- }
+ std::ranges::transform(forceLEDs, std::back_inserter(forceUpdateLEDs),
+ [](const auto& i) { return PHY_LED_PATH + i; });
auto skipLEDs = json.value("skipLEDs", empty);
- for (auto& member : skipLEDs)
- {
- skipUpdateLEDs.push_back(PHY_LED_PATH + member);
- }
+ std::ranges::transform(skipLEDs, std::back_inserter(skipUpdateLEDs),
+ [](const auto& i) { return PHY_LED_PATH + i; });
}
catch (const std::exception& e)
{
diff --git a/led-main.cpp b/led-main.cpp
index df057a5..bebe5dd 100644
--- a/led-main.cpp
+++ b/led-main.cpp
@@ -16,6 +16,7 @@
#include <sdeventplus/event.hpp>
+#include <algorithm>
#include <iostream>
int main(void)
@@ -58,11 +59,14 @@
#endif
/** Now create so many dbus objects as there are groups */
- for (auto& grp : systemLedMap)
- {
- groups.emplace_back(std::make_unique<phosphor::led::Group>(
- bus, grp.first, manager, serialize));
- }
+ std::ranges::transform(
+ systemLedMap, std::back_inserter(groups),
+ [&bus, &manager, &serialize](
+ const std::pair<std::string,
+ std::set<phosphor::led::Layout::LedAction>>& grp) {
+ return std::make_unique<phosphor::led::Group>(bus, grp.first,
+ manager, serialize);
+ });
// Attach the bus to sd_event to service user requests
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
diff --git a/serialize.hpp b/serialize.hpp
index 23cffa2..71de987 100644
--- a/serialize.hpp
+++ b/serialize.hpp
@@ -21,7 +21,7 @@
class Serialize
{
public:
- Serialize(const fs::path& path) : path(path)
+ explicit Serialize(const fs::path& path) : path(path)
{
restoreGroups();
}