Fix compilation warnings
Various small issues:
* Member initialization order
* Comparison of different signedness
* Unused parameters
* Unused variable
Change-Id: Ie59db239b4216ad089f7cf0f289e6ed3d6ac8e18
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
diff --git a/src/mdrv2.cpp b/src/mdrv2.cpp
index 1bf2e31..aba2775 100644
--- a/src/mdrv2.cpp
+++ b/src/mdrv2.cpp
@@ -225,7 +225,7 @@
}
smbiosFile.clear();
smbiosFile.seekg(0, std::ios_base::end);
- int fileLength = smbiosFile.tellg();
+ size_t fileLength = smbiosFile.tellg();
smbiosFile.seekg(0, std::ios_base::beg);
if (fileLength < sizeof(MDRSMBIOSHeader))
{
@@ -309,8 +309,9 @@
return teminate;
}
-bool MDRV2::sendDataInformation(uint8_t idIndex, uint8_t flag, uint32_t dataLen,
- uint32_t dataVer, uint32_t timeStamp)
+bool MDRV2::sendDataInformation(uint8_t idIndex, uint8_t /* flag */,
+ uint32_t dataLen, uint32_t dataVer,
+ uint32_t timeStamp)
{
if (idIndex >= maxDirEntries)
{
@@ -357,7 +358,7 @@
for (int index = 0; index < smbiosDir.dirEntries; index++)
{
- int info = 0;
+ size_t info = 0;
for (; info < arrayDataInfo.size(); info++)
{
if (arrayDataInfo[info] !=
@@ -419,7 +420,7 @@
sdbusplus::bus::match::rules::argNpath(
0,
"/xyz/openbmc_project/inventory/system/board/"),
- [this, systemInterface](sdbusplus::message_t& msg) {
+ [this](sdbusplus::message_t& msg) {
sdbusplus::message::object_path objectName;
boost::container::flat_map<
std::string,
@@ -445,8 +446,8 @@
phosphor::logging::entry("ERROR=%s", e.what()));
}
- int num = getTotalCpuSlot();
- if (num == -1)
+ std::optional<size_t> num = getTotalCpuSlot();
+ if (!num)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"get cpu total slot failed");
@@ -454,12 +455,12 @@
}
// In case the new size is smaller than old, trim the vector
- if (num < cpus.size())
+ if (*num < cpus.size())
{
- cpus.erase(cpus.begin() + num, cpus.end());
+ cpus.resize(*num);
}
- for (int index = 0; index < num; index++)
+ for (unsigned int index = 0; index < *num; index++)
{
std::string path = cpuPath + std::to_string(index);
if (index + 1 > cpus.size())
@@ -478,7 +479,7 @@
#ifdef DIMM_DBUS
num = getTotalDimmSlot();
- if (num == -1)
+ if (!num)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"get dimm total slot failed");
@@ -486,12 +487,12 @@
}
// In case the new size is smaller than old, trim the vector
- if (num < dimms.size())
+ if (*num < dimms.size())
{
- dimms.erase(dimms.begin() + num, dimms.end());
+ dimms.resize(*num);
}
- for (int index = 0; index < num; index++)
+ for (unsigned int index = 0; index < *num; index++)
{
std::string path = dimmPath + std::to_string(index);
if (index + 1 > dimms.size())
@@ -510,7 +511,7 @@
#endif
num = getTotalPcieSlot();
- if (num == -1)
+ if (!num)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"get pcie total slot failed");
@@ -518,12 +519,12 @@
}
// In case the new size is smaller than old, trim the vector
- if (num < pcies.size())
+ if (*num < pcies.size())
{
- pcies.erase(pcies.begin() + num, pcies.end());
+ pcies.resize(*num);
}
- for (int index = 0; index < num; index++)
+ for (unsigned int index = 0; index < *num; index++)
{
std::string path = pciePath + std::to_string(index);
if (index + 1 > pcies.size())
@@ -544,16 +545,16 @@
bus, systemPath, smbiosDir.dir[smbiosDirIndex].dataStorage);
}
-int MDRV2::getTotalCpuSlot()
+std::optional<size_t> MDRV2::getTotalCpuSlot()
{
uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- int num = 0;
+ size_t num = 0;
if (dataIn == nullptr)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"get cpu total slot failed - no storage data");
- return -1;
+ return std::nullopt;
}
while (1)
@@ -578,16 +579,16 @@
return num;
}
-int MDRV2::getTotalDimmSlot()
+std::optional<size_t> MDRV2::getTotalDimmSlot()
{
uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- uint8_t num = 0;
+ size_t num = 0;
if (dataIn == nullptr)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"Fail to get dimm total slot - no storage data");
- return -1;
+ return std::nullopt;
}
while (1)
@@ -612,16 +613,16 @@
return num;
}
-int MDRV2::getTotalPcieSlot()
+std::optional<size_t> MDRV2::getTotalPcieSlot()
{
uint8_t* dataIn = smbiosDir.dir[smbiosDirIndex].dataStorage;
- int num = 0;
+ size_t num = 0;
if (dataIn == nullptr)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"Fail to get total system slot - no storage data");
- return -1;
+ return std::nullopt;
}
while (1)
@@ -677,7 +678,7 @@
}
auto pos = std::distance(std::begin(buffer), it);
- auto length = smbiosTableStorageSize - pos;
+ size_t length = smbiosTableStorageSize - pos;
uint8_t foundMajorVersion;
uint8_t foundMinorVersion;