Fix the bugs found in static analysis
This commit fixes the following static analyzer reported issues:
Operands don't affect result
some conditions are not required to check as its always true
Unsigned compared against 0
Unchecked return value from library
Uninitialized scalar variable
Change-Id: I0b1fd426794bb88f6eafcc817cef5dd2f655e1ba
Signed-off-by: PavanKumarIntel <pavanx.kumar.martha@intel.com>
diff --git a/user_channel/channel_layer.cpp b/user_channel/channel_layer.cpp
index fb70f1e..85c3426 100644
--- a/user_channel/channel_layer.cpp
+++ b/user_channel/channel_layer.cpp
@@ -51,9 +51,7 @@
bool isValidAccessMode(const uint8_t accessMode)
{
- return (
- (accessMode >= static_cast<uint8_t>(EChannelAccessMode::disabled)) &&
- (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared)));
+ return (accessMode <= static_cast<uint8_t>(EChannelAccessMode::shared));
}
bool isValidChannel(const uint8_t chNum)
diff --git a/user_channel/channelcommands.cpp b/user_channel/channelcommands.cpp
index e860506..cd0a33b 100644
--- a/user_channel/channelcommands.cpp
+++ b/user_channel/channelcommands.cpp
@@ -195,7 +195,7 @@
return response(ccActionNotSupportedForChannel);
}
- ChannelAccess chAccess;
+ ChannelAccess chAccess = {};
Cc compCode = ipmi::ccUnspecifiedError;
diff --git a/user_channel/passwd_mgr.cpp b/user_channel/passwd_mgr.cpp
index 7b5b7ec..acf7c74 100644
--- a/user_channel/passwd_mgr.cpp
+++ b/user_channel/passwd_mgr.cpp
@@ -75,7 +75,10 @@
{
if ((st.st_mode & modeMask) != (S_IRUSR | S_IWUSR))
{
- chmod(passwdFileName, S_IRUSR | S_IWUSR);
+ if (chmod(passwdFileName, S_IRUSR | S_IWUSR) == -1)
+ {
+ log<level::DEBUG>("Error setting chmod for ipmi_pass file");
+ }
}
}
@@ -83,7 +86,10 @@
{
if ((st.st_mode & modeMask) != (S_IRUSR | S_IWUSR))
{
- chmod(encryptKeyFileName, S_IRUSR | S_IWUSR);
+ if (chmod(encryptKeyFileName, S_IRUSR | S_IWUSR) == -1)
+ {
+ log<level::DEBUG>("Error setting chmod for ipmi_pass file");
+ }
}
}
}