clang-tidy: fix some warnings
Resolve the following:
```
sys_info_param.cpp:12:11: style: Variable 'callback' can be declared as reference to const [constVariableReference]
auto& callback = iterator->second;
^
include/ipmid/sessionhelper.hpp:49:31: performance: Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]
sessionIdString = sessionIdString.substr(0, pos);
^
include/ipmid/sessionhelper.hpp:36:14: style: The scope of the variable 'tempSessionHandle' can be reduced. [variableScope]
uint16_t tempSessionHandle = 0;
^
include/ipmid/sessionhelper.hpp:77:47: performance: Function parameter 'objectPath' should be passed by const reference. [passedByValue]
bool isSessionObjectMatched(const std::string objectPath,
^
include/ipmid/sessionhelper.hpp:50:31: performance: Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr]
sessionIdString = sessionIdString.substr(0, pos);
^
transport/serialbridge/test/serial_unittest.cpp:21:13: style: The scope of the variable 'c' can be reduced. [variableScope]
uint8_t c;
^
```
Change-Id: I5a34fc50a95c33367e8b5d67dcb94c46b8def94a
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/include/ipmid/sessionhelper.hpp b/include/ipmid/sessionhelper.hpp
index 5c09bfc..3afb5fa 100644
--- a/include/ipmid/sessionhelper.hpp
+++ b/include/ipmid/sessionhelper.hpp
@@ -33,7 +33,6 @@
// getting the position of session id and session handle string from
// object path.
std::size_t ptrPosition = objectPath.rfind("/");
- uint16_t tempSessionHandle = 0;
if (ptrPosition != std::string::npos)
{
@@ -47,10 +46,11 @@
// extracting the session handle
std::string sessionHandleString = sessionIdString.substr(pos + 1);
// extracting the session id
- sessionIdString = sessionIdString.substr(0, pos);
+ sessionIdString.resize(pos);
// converting session id string and session handle string to
// hexadecimal.
std::stringstream handle(sessionHandleString);
+ uint16_t tempSessionHandle = 0;
handle >> std::hex >> tempSessionHandle;
sessionHandle = tempSessionHandle & 0xFF;
std::stringstream idString(sessionIdString);
@@ -74,7 +74,7 @@
*
* @return true if the object is matched else return false
**/
-bool isSessionObjectMatched(const std::string objectPath,
+bool isSessionObjectMatched(const std::string& objectPath,
const uint32_t reqSessionId,
const uint8_t reqSessionHandle)
{