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/include/mdrv2.hpp b/include/mdrv2.hpp
index e53545f..65890ed 100644
--- a/include/mdrv2.hpp
+++ b/include/mdrv2.hpp
@@ -75,7 +75,7 @@
           boost::asio::io_context& io) :
         sdbusplus::server::object_t<
             sdbusplus::server::xyz::openbmc_project::smbios::MDRV2>(bus, path),
-        bus(bus), timer(io), smbiosInterface(getObjectServer().add_interface(
+        timer(io), bus(bus), smbiosInterface(getObjectServer().add_interface(
                                  smbiosPath, smbiosInterfaceName))
     {
         smbiosDir.agentVersion = smbiosAgentVersion;
@@ -143,9 +143,9 @@
     inline uint8_t smbiosValidFlag(uint8_t index);
     void systemInfoUpdate(void);
 
-    int getTotalCpuSlot(void);
-    int getTotalDimmSlot(void);
-    int getTotalPcieSlot(void);
+    std::optional<size_t> getTotalCpuSlot(void);
+    std::optional<size_t> getTotalDimmSlot(void);
+    std::optional<size_t> getTotalPcieSlot(void);
     std::vector<std::unique_ptr<Cpu>> cpus;
     std::vector<std::unique_ptr<Dimm>> dimms;
     std::vector<std::unique_ptr<Pcie>> pcies;
diff --git a/include/system.hpp b/include/system.hpp
index 992408e..4753a01 100644
--- a/include/system.hpp
+++ b/include/system.hpp
@@ -45,11 +45,10 @@
         sdbusplus::server::object_t<
             sdbusplus::server::xyz::openbmc_project::common::UUID>(
             bus, objPath.c_str()),
-        bus(bus),
         sdbusplus::server::object_t<sdbusplus::server::xyz::openbmc_project::
                                         inventory::decorator::Revision>(
             bus, objPath.c_str()),
-        path(objPath), storage(smbiosTableStorage)
+        bus(bus), path(objPath), storage(smbiosTableStorage)
     {
         std::string input = "0";
         uuid(input);
diff --git a/src/cpu.cpp b/src/cpu.cpp
index ed4eabb..d9fd212 100644
--- a/src/cpu.cpp
+++ b/src/cpu.cpp
@@ -108,7 +108,7 @@
     {
         if (charBits.test(index))
         {
-            if (cap = characteristicsTable[index])
+            if ((cap = characteristicsTable[index]))
             {
                 result.emplace_back(*cap);
             }
diff --git a/src/cpuinfo_main.cpp b/src/cpuinfo_main.cpp
index 5fa1c06..c54cdb6 100644
--- a/src/cpuinfo_main.cpp
+++ b/src/cpuinfo_main.cpp
@@ -578,7 +578,7 @@
             "type='signal',interface='org.freedesktop.DBus.Properties',member='"
             "PropertiesChanged',arg0='xyz.openbmc_project."
             "Configuration.XeonCPU'",
-            [&io, conn, &objServer](sdbusplus::message_t& msg) {
+            [&io, conn, &objServer](sdbusplus::message_t& /* msg */) {
         std::cerr << "get cpu configuration match\n";
         static boost::asio::steady_timer filterTimer(io);
         filterTimer.expires_after(std::chrono::seconds(configCheckInterval));
@@ -642,7 +642,7 @@
 
 } // namespace cpu_info
 
-int main(int argc, char* argv[])
+int main()
 {
     // setup connection to dbus
     boost::asio::io_service& io = cpu_info::dbus::getIOContext();
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;
 
diff --git a/src/smbios-ipmi-blobs/handler.cpp b/src/smbios-ipmi-blobs/handler.cpp
index 8bd7daf..4b1841f 100644
--- a/src/smbios-ipmi-blobs/handler.cpp
+++ b/src/smbios-ipmi-blobs/handler.cpp
@@ -74,7 +74,7 @@
     return std::vector<std::string>(1, blobId);
 }
 
-bool SmbiosBlobHandler::deleteBlob(const std::string& path)
+bool SmbiosBlobHandler::deleteBlob(const std::string& /* path */)
 {
     return false;
 }
@@ -111,8 +111,9 @@
     return true;
 }
 
-std::vector<uint8_t> SmbiosBlobHandler::read(uint16_t session, uint32_t offset,
-                                             uint32_t requestedSize)
+std::vector<uint8_t> SmbiosBlobHandler::read(uint16_t /* session */,
+                                             uint32_t /* offset */,
+                                             uint32_t /* requestedSize */)
 {
     /* SMBIOS blob handler does not support read. */
     return std::vector<uint8_t>();
@@ -157,8 +158,8 @@
     return true;
 }
 
-bool SmbiosBlobHandler::writeMeta(uint16_t session, uint32_t offset,
-                                  const std::vector<uint8_t>& data)
+bool SmbiosBlobHandler::writeMeta(uint16_t /* session */, uint32_t /* offset */,
+                                  const std::vector<uint8_t>& /* data */)
 {
     return false;
 }
diff --git a/src/system.cpp b/src/system.cpp
index 3e4b69c..c0713a6 100644
--- a/src/system.cpp
+++ b/src/system.cpp
@@ -34,7 +34,7 @@
 namespace smbios
 {
 
-std::string System::uuid(std::string value)
+std::string System::uuid(std::string /* value */)
 {
     uint8_t* dataIn = storage;
     dataIn = getSMBIOSTypePtr(dataIn, systemType);
@@ -120,7 +120,7 @@
     bus.call_noreply(method);
 }
 
-std::string System::version(std::string value)
+std::string System::version(std::string /* value */)
 {
     std::string result = "No BIOS Version";
     uint8_t* dataIn = storage;
@@ -128,7 +128,6 @@
     if (dataIn != nullptr)
     {
         auto biosInfo = reinterpret_cast<struct BIOSInfo*>(dataIn);
-        uint8_t biosVerByte = biosInfo->biosVersion;
         std::string tempS = positionToString(biosInfo->biosVersion,
                                              biosInfo->length, dataIn);
         if (std::find_if(tempS.begin(), tempS.end(),