Fix some warnings by cppcheck
Warning message:
../../../occ_events.hpp:16:9: warning: Value stored to 'event' is never read [deadcode.DeadStores]
event = sd_event_unref(event);
^ ~~~~~~~~~~~~~~~~~~~~~
../../../occ_events.hpp:26:9: warning: Value stored to 'eventSource' is never read [deadcode.DeadStores]
eventSource = sd_event_source_unref(eventSource);
occ_dbus.cpp:34:47: performance: Searching before insertion is not necessary. [stlFindInsert]
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
^
occ_dbus.cpp:61:47: performance: Searching before insertion is not necessary. [stlFindInsert]
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
^
occ_dbus.cpp:88:47: performance: Searching before insertion is not necessary. [stlFindInsert]
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
^
occ_dbus.cpp:115:47: performance: Searching before insertion is not necessary. [stlFindInsert]
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
^
occ_dbus.cpp:158:80: performance: Searching before insertion is not necessary. [stlFindInsert]
operationalStatus.emplace(path, std::make_unique<OperationalStatusIntf>(
^
occ_pass_through.hpp:42:5: style: Class 'PassThrough' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
PassThrough(const char* path);
^
powercap.hpp:41:5: style: Class 'PowerCap' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
PowerCap(Status& occStatus,
^
occ_manager.hpp:77:5: style: Struct 'Manager' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
Manager(EventPtr& event) :
^
occ_status.hpp:307:26: style: Local variable 'path' shadows outer variable [shadowVariable]
auto path = fs::path(estimatedPath);
^
occ_status.hpp:207:17: note: Shadowed declaration
std::string path;
^
occ_status.hpp:307:26: note: Shadow variable
auto path = fs::path(estimatedPath);
^
pldm.hpp:55:14: warning: Member variable 'Interface::OCCSensorOffset' is not initialized in the constructor. [uninitMemberVar]
explicit Interface(
^
pldm.hpp:55:14: warning: Member variable 'Interface::SBESensorOffset' is not initialized in the constructor. [uninitMemberVar]
explicit Interface(
^
powermode.hpp:60:5: style: Class 'PowerMode' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
PowerMode(Status& occStatus) :
^
powermode.hpp:96:5: style: Class 'PowerIPS' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
PowerIPS(Status& occStatus) :
^
occ_manager.cpp:321:24: style: The scope of the variable 'path' can be reduced. [variableScope]
constexpr auto path = "/org/openpower/dump";
^
occ_manager.cpp:322:24: style: The scope of the variable 'interface' can be reduced. [variableScope]
constexpr auto interface = "xyz.openbmc_project.Dump.Create";
^
occ_manager.cpp:323:24: style: The scope of the variable 'function' can be reduced. [variableScope]
constexpr auto function = "CreateDump";
^
pldm.cpp:78:16: style: Local variable 'pdr' shadows outer variable [shadowVariable]
for (auto& pdr : pdrs)
^
pldm.cpp:48:10: note: Shadowed declaration
auto pdr =
^
pldm.cpp:78:16: note: Shadow variable
for (auto& pdr : pdrs)
^
pldm.cpp:248:16: style: Local variable 'pdr' shadows outer variable [shadowVariable]
for (auto& pdr : pdrs)
^
pldm.cpp:221:10: note: Shadowed declaration
auto pdr =
^
pldm.cpp:248:16: note: Shadow variable
for (auto& pdr : pdrs)
^
powermode.cpp:28:22: style: Variable 'pmode' is assigned a value that is never used. [unreadVariable]
SysPwrMode pmode = SysPwrMode::NO_CHANGE;
Tested: Use cppcheck to build successfully and eliminate the above
warning message.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I72751dc94db684fc558b4bb57b1924be64ce6760
diff --git a/file.hpp b/file.hpp
index 9ad5213..7e65758 100644
--- a/file.hpp
+++ b/file.hpp
@@ -25,7 +25,7 @@
*
* @param[in] fd - File descriptor
*/
- FileDescriptor(int fd) : fd(fd)
+ explicit FileDescriptor(int fd) : fd(fd)
{
// Nothing
}
diff --git a/occ_dbus.cpp b/occ_dbus.cpp
index aaaf1c6..6bc1a46 100644
--- a/occ_dbus.cpp
+++ b/occ_dbus.cpp
@@ -28,7 +28,7 @@
return false;
}
- if (sensors.find(path) == sensors.end())
+ if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
@@ -55,7 +55,7 @@
return false;
}
- if (sensors.find(path) == sensors.end())
+ if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
@@ -82,7 +82,7 @@
return false;
}
- if (sensors.find(path) == sensors.end())
+ if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
@@ -109,7 +109,7 @@
return false;
}
- if (sensors.find(path) == sensors.end())
+ if (!sensors.contains(path))
{
sensors.emplace(
path, std::make_unique<SensorIntf>(utils::getBus(), path.c_str()));
@@ -153,7 +153,7 @@
return false;
}
- if (operationalStatus.find(path) == operationalStatus.end())
+ if (!operationalStatus.contains(path))
{
operationalStatus.emplace(path, std::make_unique<OperationalStatusIntf>(
utils::getBus(), path.c_str()));
diff --git a/occ_events.hpp b/occ_events.hpp
index 26318e8..aa0120c 100644
--- a/occ_events.hpp
+++ b/occ_events.hpp
@@ -13,7 +13,7 @@
{
void operator()(sd_event* event) const
{
- event = sd_event_unref(event);
+ sd_event_unref(event);
}
};
using EventPtr = std::unique_ptr<sd_event, EventDeleter>;
@@ -23,7 +23,7 @@
{
void operator()(sd_event_source* eventSource) const
{
- eventSource = sd_event_source_unref(eventSource);
+ sd_event_source_unref(eventSource);
}
};
using EventSourcePtr = std::unique_ptr<sd_event_source, EventSourceDeleter>;
diff --git a/occ_manager.cpp b/occ_manager.cpp
index 33711be..9b6f1c5 100644
--- a/occ_manager.cpp
+++ b/occ_manager.cpp
@@ -318,10 +318,6 @@
if (sbeCanDump(instance))
{
- constexpr auto path = "/org/openpower/dump";
- constexpr auto interface = "xyz.openbmc_project.Dump.Create";
- constexpr auto function = "CreateDump";
-
log<level::INFO>("HRESET failed, triggering SBE dump",
entry("SBE=%d", instance));
@@ -333,6 +329,10 @@
try
{
+ constexpr auto path = "/org/openpower/dump";
+ constexpr auto interface = "xyz.openbmc_project.Dump.Create";
+ constexpr auto function = "CreateDump";
+
std::string service = utils::getService(path, interface);
auto method =
bus.new_method_call(service.c_str(), path, interface, function);
diff --git a/occ_manager.hpp b/occ_manager.hpp
index 97bf2b1..e9a469c 100644
--- a/occ_manager.hpp
+++ b/occ_manager.hpp
@@ -74,7 +74,7 @@
*
* @param[in] event - Unique ptr reference to sd_event
*/
- Manager(EventPtr& event) :
+ explicit Manager(EventPtr& event) :
event(event), pollInterval(defaultPollingInterval),
sdpEvent(sdeventplus::Event::get_default()),
_pollTimer(
diff --git a/occ_pass_through.hpp b/occ_pass_through.hpp
index 185db79..a1e1e91 100644
--- a/occ_pass_through.hpp
+++ b/occ_pass_through.hpp
@@ -39,7 +39,7 @@
/** @brief Ctor to put pass-through d-bus object on the bus
* @param[in] path - Path to attach at
*/
- PassThrough(const char* path);
+ explicit PassThrough(const char* path);
/** @brief Pass through command to OCC from dbus
* @param[in] command - command to pass-through
diff --git a/occ_status.hpp b/occ_status.hpp
index 1cbcdb3..e8e4530 100644
--- a/occ_status.hpp
+++ b/occ_status.hpp
@@ -304,9 +304,9 @@
auto& name = std::get<1>(it->second);
if (!name.empty() && name != "None")
{
- auto path = fs::path(estimatedPath);
- path.replace_filename(name);
- return path.string();
+ auto objectPath = fs::path(estimatedPath);
+ objectPath.replace_filename(name);
+ return objectPath.string();
}
}
}
diff --git a/pldm.cpp b/pldm.cpp
index 6c177fc..43b86ab 100644
--- a/pldm.cpp
+++ b/pldm.cpp
@@ -45,10 +45,11 @@
}
bool offsetFound = false;
- auto pdr =
+ auto stateSensorPDR =
reinterpret_cast<const pldm_state_sensor_pdr*>(pdrs.front().data());
- auto possibleStatesPtr = pdr->possible_states;
- for (auto offset = 0; offset < pdr->composite_sensor_count; offset++)
+ auto possibleStatesPtr = stateSensorPDR->possible_states;
+ for (auto offset = 0; offset < stateSensorPDR->composite_sensor_count;
+ offset++)
{
auto possibleStates =
reinterpret_cast<const state_sensor_possible_states*>(
@@ -218,10 +219,11 @@
}
bool offsetFound = false;
- auto pdr =
+ auto stateEffecterPDR =
reinterpret_cast<const pldm_state_effecter_pdr*>(pdrs.front().data());
- auto possibleStatesPtr = pdr->possible_states;
- for (auto offset = 0; offset < pdr->composite_effecter_count; offset++)
+ auto possibleStatesPtr = stateEffecterPDR->possible_states;
+ for (auto offset = 0; offset < stateEffecterPDR->composite_effecter_count;
+ offset++)
{
auto possibleStates =
reinterpret_cast<const state_effecter_possible_states*>(
@@ -230,7 +232,7 @@
if (possibleStates->state_set_id == stateSetId)
{
stateIdPos = offset;
- effecterCount = pdr->composite_effecter_count;
+ effecterCount = stateEffecterPDR->composite_effecter_count;
offsetFound = true;
break;
}
diff --git a/pldm.hpp b/pldm.hpp
index 2f861b8..ccfb3f9 100644
--- a/pldm.hpp
+++ b/pldm.hpp
@@ -157,12 +157,12 @@
/** @brief Sensor offset of OCC state set ID
* PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS in state sensor PDR.
*/
- SensorOffset OCCSensorOffset;
+ SensorOffset OCCSensorOffset = 0;
/** @brief Sensor offset of the SBE state set ID
* PLDM_OEM_IBM_SBE_HRESET_STATE in state sensor PDR.
*/
- SensorOffset SBESensorOffset;
+ SensorOffset SBESensorOffset = 0;
/** @brief OCC Instance mapping to PLDM Effecter ID
*/
diff --git a/powercap.hpp b/powercap.hpp
index 58070ba..6dab352 100644
--- a/powercap.hpp
+++ b/powercap.hpp
@@ -38,8 +38,8 @@
*
* @param[in] occStatus - The occ status object
*/
- PowerCap(Status& occStatus,
- const std::string& occMasterName = OCC_MASTER_NAME) :
+ explicit PowerCap(Status& occStatus,
+ const std::string& occMasterName = OCC_MASTER_NAME) :
occMasterName(occMasterName),
occStatus(occStatus),
pcapMatch(
diff --git a/powermode.cpp b/powermode.cpp
index a78c37e..e87b921 100644
--- a/powermode.cpp
+++ b/powermode.cpp
@@ -25,8 +25,6 @@
return;
}
- SysPwrMode pmode = SysPwrMode::NO_CHANGE;
-
std::map<std::string, std::variant<std::string>> properties{};
std::string interface;
std::string propVal;
@@ -36,9 +34,8 @@
{
auto modeEntryValue = modeEntry->second;
propVal = std::get<std::string>(modeEntryValue);
- pmode = convertStringToMode(propVal);
- if (pmode != SysPwrMode::NO_CHANGE)
+ if (convertStringToMode(propVal) != SysPwrMode::NO_CHANGE)
{
log<level::INFO>(
fmt::format("Power Mode Change Requested: {}", propVal)
diff --git a/powermode.hpp b/powermode.hpp
index c9d3f0e..0d337dc 100644
--- a/powermode.hpp
+++ b/powermode.hpp
@@ -57,7 +57,7 @@
*
* @param[in] occStatus - The occ status object
*/
- PowerMode(Status& occStatus) :
+ explicit PowerMode(Status& occStatus) :
occStatus(occStatus),
pmodeMatch(utils::getBus(),
sdbusplus::bus::match::rules::propertiesChanged(
@@ -93,7 +93,7 @@
*
* @param[in] occStatus - The occ status object
*/
- PowerIPS(Status& occStatus) :
+ explicit PowerIPS(Status& occStatus) :
occStatus(occStatus),
ipsMatch(utils::getBus(),
sdbusplus::bus::match::rules::propertiesChanged(