Fix some warnings by cppcheck
Warning message:
/src/manager.cpp:255:53: warning: Division by zero [core.DivideZero]
if (((std::abs(attrValue - lowerBound)) % scalarIncrement) != 0)
include/password.hpp:84:36: performance: Function parameter 'rawData'
should be passed by const reference. [passedByValue]
const std::string rawData, const std::string algo);
^
include/password.hpp:84:63: performance: Function parameter 'algo'
should be passed by const reference. [passedByValue]
const std::string rawData, const std::string algo);
Tested: Verify that there are no such warnings in local CI.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I12276f64b06e4eddfd8cd340ebc16d04e4e9ccd5
diff --git a/include/password.hpp b/include/password.hpp
index 8d4e00e..ee7ace3 100644
--- a/include/password.hpp
+++ b/include/password.hpp
@@ -81,7 +81,7 @@
std::string newPassword);
bool isMatch(const std::array<uint8_t, maxHashSize>& expected,
const std::array<uint8_t, maxSeedSize>& seed,
- const std::string rawData, const std::string algo);
+ const std::string& rawData, const std::string& algo);
sdbusplus::asio::object_server& objServer;
std::shared_ptr<sdbusplus::asio::connection>& systemBus;
std::filesystem::path seedFile;
diff --git a/src/manager.cpp b/src/manager.cpp
index 89727e6..1a68898 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -252,7 +252,8 @@
throw InvalidArgument();
}
- if (((std::abs(attrValue - lowerBound)) % scalarIncrement) != 0)
+ if (scalarIncrement == 0 ||
+ ((std::abs(attrValue - lowerBound)) % scalarIncrement) != 0)
{
lg2::error(
"((std::abs({ATTR_VALUE} - {LOWER_BOUND})) % {SCALAR_INCREMENT}) != 0",
diff --git a/src/password.cpp b/src/password.cpp
index 5231120..f780cc5 100644
--- a/src/password.cpp
+++ b/src/password.cpp
@@ -35,7 +35,7 @@
bool Password::isMatch(const std::array<uint8_t, maxHashSize>& expected,
const std::array<uint8_t, maxSeedSize>& seed,
- const std::string rawData, const std::string algo)
+ const std::string& rawData, const std::string& algo)
{
lg2::error("isMatch");