Fix some warnings by cppcheck
Warning message:
```
dbusSensor.hpp:28:9: performance: Variable 'servName' is assigned in
constructor body. Consider performing initialization in
initialization list. [useInitializationList]
servName = getService(bus, path, sensorIntf);
^
virtualSensor.hpp:69:55: performance: Function parameter 'path'
should be passed by const reference. [passedByValue]
SensorParam(sdbusplus::bus::bus& bus, std::string path, void* ctx):
^
virtualSensor.hpp:271:44: performance: Function parameter
'configFile' should be passed by const reference. [passedByValue]
Json parseConfigFile(const std::string configFile);
^
virtualSensor.cpp:334:26: style: Local variable 'objPath' shadows
outer argument [shadowArgument]
auto objPath = sensorDbusPath + sensorType + "/" + name;
^
virtualSensor.cpp:255:58: note: Shadowed declaration
const std::string& objPath)
^
virtualSensor.cpp:334:26: note: Shadow variable
auto objPath = sensorDbusPath + sensorType + "/" + name;
^
virtualSensor.cpp:338:33: style: Local variable 'name' shadows outer
variable [shadowVariable]
std::string name = j["ParamName"];
^
virtualSensor.cpp:330:29: note: Shadowed declaration
std::string name = desc.value("Name", "");
^
virtualSensor.cpp:338:33: note: Shadow variable
std::string name = j["ParamName"];
^
virtualSensor.cpp:649:56: performance: Function parameter
'configFile' should be passed by const reference. [passedByValue]
Json VirtualSensors::parseConfigFile(const std::string configFile)
```
Tested: Verify that there are no such warnings in local CI.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I8afaf35043c97d0ca6bfcbe9d50c847d126f8e2d
diff --git a/dbusSensor.hpp b/dbusSensor.hpp
index ba2e15e..bfda9b0 100644
--- a/dbusSensor.hpp
+++ b/dbusSensor.hpp
@@ -24,9 +24,7 @@
bus,
sdbusplus::bus::match::rules::propertiesChanged(path, sensorIntf),
handleDbusSignal, ctx)
- {
- servName = getService(bus, path, sensorIntf);
- }
+ {}
/** @brief Get sensor value property from D-bus interface */
double getSensorValue()
@@ -55,9 +53,9 @@
/** @brief sdbusplus bus client connection. */
sdbusplus::bus::bus& bus;
/** @brief complete path for sensor */
- std::string path;
+ std::string path{};
/** @brief service name for the sensor daemon */
- std::string servName;
+ std::string servName{};
/** @brief signal for sensor value change */
sdbusplus::bus::match_t signal;
};
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index 33206e2..4ce18a9 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -331,13 +331,13 @@
if (!sensorType.empty() && !name.empty())
{
- auto objPath = sensorDbusPath + sensorType + "/" + name;
+ auto path = sensorDbusPath + sensorType + "/" + name;
auto paramPtr =
- std::make_unique<SensorParam>(bus, objPath, this);
- std::string name = j["ParamName"];
- symbols.create_variable(name);
- paramMap.emplace(std::move(name), std::move(paramPtr));
+ std::make_unique<SensorParam>(bus, path, this);
+ std::string paramName = j["ParamName"];
+ symbols.create_variable(paramName);
+ paramMap.emplace(std::move(paramName), std::move(paramPtr));
}
}
}
@@ -646,7 +646,7 @@
}
/** @brief Parsing Virtual Sensor config JSON file */
-Json VirtualSensors::parseConfigFile(const std::string configFile)
+Json VirtualSensors::parseConfigFile(const std::string& configFile)
{
std::ifstream jsonFile(configFile);
if (!jsonFile.is_open())
diff --git a/virtualSensor.hpp b/virtualSensor.hpp
index cdf1d97..cff46f7 100644
--- a/virtualSensor.hpp
+++ b/virtualSensor.hpp
@@ -66,7 +66,7 @@
* @param[in] path - The Dbus path of sensor
* @param[in] ctx - sensor context for update
*/
- SensorParam(sdbusplus::bus::bus& bus, std::string path, void* ctx) :
+ SensorParam(sdbusplus::bus::bus& bus, const std::string& path, void* ctx) :
dbusSensor(std::make_unique<DbusSensor>(bus, path, ctx)),
paramType(dbusParam)
{}
@@ -268,7 +268,7 @@
/** @brief Get virual sensor config from DBus**/
ManagedObjectType getObjectsFromDBus();
/** @brief Parsing virtual sensor config JSON file */
- Json parseConfigFile(const std::string configFile);
+ Json parseConfigFile(const std::string& configFile);
/** @brief Matches for virtual sensors */
std::vector<std::unique_ptr<sdbusplus::bus::match::match>> matches;