tools: Fix some warnings by cppcheck
Warning message:
tools/i2c/i2c.hpp:30:9: performance: Variable 'busStr' is assigned in
constructor body. Consider performing initialization in
initialization list. [useInitializationList]
busStr = "/dev/i2c-" + std::to_string(busId);
^
tools/power-utils/updater.cpp:213:18: style: Local variable 'devPath'
shadows outer variable [shadowVariable]
auto devPath = internal::getDevicePath(p);
^
tools/power-utils/updater.hpp:108:17: note: Shadowed declaration
std::string devPath;
^
tools/power-utils/updater.cpp:213:18: note: Shadow variable
auto devPath = internal::getDevicePath(p);
^
Tested: Verify that there are no such warnings in local CI.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ibc7536345ee40579256c398646ad00a05b686ab3
diff --git a/tools/i2c/i2c.hpp b/tools/i2c/i2c.hpp
index 23acdbc..5a01ebf 100644
--- a/tools/i2c/i2c.hpp
+++ b/tools/i2c/i2c.hpp
@@ -25,9 +25,9 @@
InitialState initialState = InitialState::OPEN,
int maxRetries = 0) :
busId(busId),
- devAddr(devAddr), maxRetries(maxRetries)
+ devAddr(devAddr), maxRetries(maxRetries),
+ busStr("/dev/i2c-" + std::to_string(busId))
{
- busStr = "/dev/i2c-" + std::to_string(busId);
if (initialState == InitialState::OPEN)
{
open();
diff --git a/tools/power-utils/updater.cpp b/tools/power-utils/updater.cpp
index 1ddde12..0b33c95 100644
--- a/tools/power-utils/updater.cpp
+++ b/tools/power-utils/updater.cpp
@@ -210,8 +210,8 @@
// directly read the debugfs to get the status.
try
{
- auto devPath = internal::getDevicePath(p);
- PMBus pmbus(devPath);
+ auto path = internal::getDevicePath(p);
+ PMBus pmbus(path);
uint16_t statusWord = pmbus.read(STATUS_WORD, Type::Debug);
auto status0Vout = pmbus.insertPageNum(STATUS_VOUT, 0);
uint8_t voutStatus = pmbus.read(status0Vout, Type::Debug);