bmcweb: Fix a bunch of warnings

bmcweb classically has not taken a strong opinion on warnings.  With
this commit, that policy is changing, and bmcweb will invoke the best
warnings we are able to enable, and turn on -Werror for all builds.

This is intended to reduce the likelihood of hard-to-debug situations
that the compiler coulve caught early on.

Change-Id: I57474410821e82666b3a108cfd0db7d070e8900a
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp
index 3b20c9f..15e1af4 100644
--- a/redfish-core/include/privileges.hpp
+++ b/redfish-core/include/privileges.hpp
@@ -34,10 +34,10 @@
     "Login", "ConfigureManager", "ConfigureComponents", "ConfigureSelf",
     "ConfigureUsers"};
 
-constexpr const int basePrivilegeCount = basePrivileges.size();
+constexpr const size_t basePrivilegeCount = basePrivileges.size();
 
 /** @brief Max number of privileges per type  */
-constexpr const int maxPrivilegeCount = 32;
+constexpr const size_t maxPrivilegeCount = 32;
 
 /** @brief A vector of all privilege names and their indexes */
 static const std::vector<std::string> privilegeNames{basePrivileges.begin(),
@@ -96,7 +96,7 @@
      */
     bool setSinglePrivilege(const char* privilege)
     {
-        for (int searchIndex = 0; searchIndex < privilegeNames.size();
+        for (size_t searchIndex = 0; searchIndex < privilegeNames.size();
              searchIndex++)
         {
             if (privilege == privilegeNames[searchIndex])
@@ -136,8 +136,8 @@
     {
         std::vector<const std::string*> activePrivileges;
 
-        int searchIndex = 0;
-        int endIndex = basePrivilegeCount;
+        size_t searchIndex = 0;
+        size_t endIndex = basePrivilegeCount;
         if (type == PrivilegeType::OEM)
         {
             searchIndex = basePrivilegeCount - 1;
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 476e03a..b992018 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -302,7 +302,8 @@
                         boost::container::flat_set<IPv4AddressData>::iterator,
                         bool>
                         it = ipv4_config.insert(
-                            {objpath.first.str.substr(ipv4PathStart.size())});
+                            {objpath.first.str.substr(ipv4PathStart.size()), "",
+                             "", "", "", "", LinkType::Local});
                     IPv4AddressData &ipv4_address = *it.first;
                     for (auto &property : interface.second)
                     {
@@ -478,45 +479,6 @@
 }
 
 /**
- * @brief Changes IPv4 address type property (Address, Gateway)
- *
- * @param[in] ifaceId     Id of interface whose IP should be modified
- * @param[in] ipIdx       Index of IP in input array that should be modified
- * @param[in] ipHash      DBus Hash id of modified IP
- * @param[in] name        Name of field in JSON representation
- * @param[in] newValue    New value that should be written
- * @param[io] asyncResp   Response object that will be returned to client
- *
- * @return true if give IP is valid and has been sent do D-Bus, false
- * otherwise
- */
-inline void changeIPv4AddressProperty(
-    const std::string &ifaceId, int ipIdx, const std::string &ipHash,
-    const std::string &name, const std::string &newValue,
-    const std::shared_ptr<AsyncResp> asyncResp)
-{
-    auto callback = [asyncResp, ipIdx, name{std::string(name)},
-                     newValue{std::move(newValue)}](
-                        const boost::system::error_code ec) {
-        if (ec)
-        {
-            messages::internalError(asyncResp->res);
-        }
-        else
-        {
-            asyncResp->res.jsonValue["IPv4Addresses"][ipIdx][name] = newValue;
-        }
-    };
-
-    crow::connections::systemBus->async_method_call(
-        std::move(callback), "xyz.openbmc_project.Network",
-        "/xyz/openbmc_project/network/" + ifaceId + "/ipv4/" + ipHash,
-        "org.freedesktop.DBus.Properties", "Set",
-        "xyz.openbmc_project.Network.IP", name,
-        std::variant<std::string>(newValue));
-}
-
-/**
  * @brief Changes IPv4 address origin property
  *
  * @param[in] ifaceId       Id of interface whose IP should be modified
@@ -530,7 +492,7 @@
  * @return true if give IP is valid and has been sent do D-Bus, false
  * otherwise
  */
-inline void changeIPv4Origin(const std::string &ifaceId, int ipIdx,
+inline void changeIPv4Origin(const std::string &ifaceId, size_t ipIdx,
                              const std::string &ipHash,
                              const std::string &newValue,
                              const std::string &newValueDbus,
@@ -570,7 +532,8 @@
  *
  * @return None
  */
-inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId, int ipIdx,
+inline void changeIPv4SubnetMaskProperty(const std::string &ifaceId,
+                                         size_t ipIdx,
                                          const std::string &ipHash,
                                          const std::string &newValueStr,
                                          uint8_t &newValue,
@@ -637,9 +600,8 @@
  *
  * @return None
  */
-inline void createIPv4(const std::string &ifaceId, unsigned int ipIdx,
-                       uint8_t subnetMask, const std::string &gateway,
-                       const std::string &address,
+inline void createIPv4(const std::string &ifaceId, uint8_t subnetMask,
+                       const std::string &gateway, const std::string &address,
                        std::shared_ptr<AsyncResp> asyncResp)
 {
     auto createIpHandler = [asyncResp](const boost::system::error_code ec) {
@@ -1099,6 +1061,7 @@
             if (gateway)
             {
                 if (!ipv4VerifyIpAndGetBitcount(*gateway))
+
                 {
                     messages::propertyValueFormatError(asyncResp->res, *gateway,
                                                        pathString + "/Gateway");
@@ -1198,8 +1161,7 @@
                     continue;
                 }
 
-                createIPv4(ifaceId, entryIdx, prefixLength, *gateway, *address,
-                           asyncResp);
+                createIPv4(ifaceId, entryIdx, *gateway, *address, asyncResp);
 
                 nlohmann::json &ipv4AddressJson =
                     asyncResp->res.jsonValue["IPv4Addresses"][entryIdx];
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 61cbd9e..b07d6b1 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -46,8 +46,8 @@
     size_t length = 0;
     int ret = 0;
     // Get the metadata from the requested field of the journal entry
-    ret = sd_journal_get_data(journal, field.data(), (const void **)&data,
-                              &length);
+    ret = sd_journal_get_data(journal, field.data(),
+                              reinterpret_cast<const void **>(&data), &length);
     if (ret < 0)
     {
         return ret;
@@ -70,7 +70,7 @@
     {
         return ret;
     }
-    contents = strtol(metadata.data(), nullptr, base);
+    contents = static_cast<int>(strtol(metadata.data(), nullptr, base));
     return ret;
 }
 
@@ -215,12 +215,12 @@
         {
             index = std::stoul(std::string(indexStr), &pos);
         }
-        catch (std::invalid_argument)
+        catch (std::invalid_argument &)
         {
             messages::resourceMissingAtURI(res, entryID);
             return false;
         }
-        catch (std::out_of_range)
+        catch (std::out_of_range &)
         {
             messages::resourceMissingAtURI(res, entryID);
             return false;
@@ -237,12 +237,12 @@
     {
         timestamp = std::stoull(std::string(tsStr), &pos);
     }
-    catch (std::invalid_argument)
+    catch (std::invalid_argument &)
     {
         messages::resourceMissingAtURI(res, entryID);
         return false;
     }
-    catch (std::out_of_range)
+    catch (std::out_of_range &)
     {
         messages::resourceMissingAtURI(res, entryID);
         return false;
@@ -382,8 +382,8 @@
             {
                 continue;
             }
-            int argNum = std::strtoul(field.data(), nullptr, 10);
-            if (argNum == 0)
+            unsigned long argNum = std::strtoul(field.data(), nullptr, 10);
+            if (argNum == 0 || argNum > std::numeric_limits<size_t>::max())
             {
                 continue;
             }
@@ -392,7 +392,7 @@
             // Make sure we have enough space in messageArgs
             if (argNum > messageArgs.size())
             {
-                messageArgs.resize(argNum);
+                messageArgs.resize(static_cast<size_t>(argNum));
             }
             messageArgs[argNum - 1] = std::string(field);
         }
@@ -482,7 +482,7 @@
         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
             journalTmp, sd_journal_close);
         journalTmp = nullptr;
-        uint64_t entryCount = 0;
+        long entryCount = 0;
         SD_JOURNAL_FOREACH(journal.get())
         {
             // Look for only journal entries that contain a REDFISH_MESSAGE_ID
@@ -803,7 +803,7 @@
         std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
             journalTmp, sd_journal_close);
         journalTmp = nullptr;
-        uint64_t entryCount = 0;
+        long entryCount = 0;
         SD_JOURNAL_FOREACH(journal.get())
         {
             entryCount++;
@@ -1094,7 +1094,7 @@
             messages::internalError(asyncResp->res);
             return;
         }
-        const uint8_t logId = std::atoi(params[0].c_str());
+        const int logId = std::atoi(params[0].c_str());
         auto getStoredLogCallback = [asyncResp, logId](
                                         const boost::system::error_code ec,
                                         const std::variant<std::string> &resp) {
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index f9c2f38..0aa4478 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -785,10 +785,10 @@
             for (auto& step : *steps)
             {
                 double target;
-                double output;
+                double out;
 
                 if (!redfish::json_util::readJson(step, response->res, "Target",
-                                                  target, "Output", output))
+                                                  target, "Output", out))
                 {
                     BMCWEB_LOG_ERROR << "Line:" << __LINE__
                                      << ", Illegal Property "
@@ -796,7 +796,7 @@
                     return CreatePIDRet::fail;
                 }
                 readings.emplace_back(target);
-                outputs.emplace_back(output);
+                outputs.emplace_back(out);
             }
             output["Reading"] = std::move(readings);
             output["Output"] = std::move(outputs);
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index b1df101..78f1d8a 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -38,9 +38,8 @@
     }
 
   private:
-    std::initializer_list<const char*> typeList = {
-        "/xyz/openbmc_project/sensors/voltage",
-        "/xyz/openbmc_project/sensors/power"};
+    std::vector<const char*> typeList = {"/xyz/openbmc_project/sensors/voltage",
+                                         "/xyz/openbmc_project/sensors/power"};
     void doGet(crow::Response& res, const crow::Request& req,
                const std::vector<std::string>& params) override
     {
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index bbed047..51895ee 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -49,7 +49,7 @@
 {
   public:
     SensorsAsyncResp(crow::Response& response, const std::string& chassisId,
-                     const std::initializer_list<const char*> types,
+                     const std::vector<const char*> types,
                      const std::string& subNode) :
         res(response),
         chassisId(chassisId), types(types), chassisSubNode(subNode)
@@ -539,11 +539,11 @@
         auto interfaceProperties = interfacesDict.find(std::get<0>(p));
         if (interfaceProperties != interfacesDict.end())
         {
-            auto valueIt = interfaceProperties->second.find(std::get<1>(p));
-            if (valueIt != interfaceProperties->second.end())
+            auto valIt = interfaceProperties->second.find(std::get<1>(p));
+            if (valIt != interfaceProperties->second.end())
             {
-                const SensorVariant& valueVariant = valueIt->second;
-                nlohmann::json& valueIt = sensor_json[std::get<2>(p)];
+                const SensorVariant& valueVariant = valIt->second;
+                nlohmann::json& jValueIt = sensor_json[std::get<2>(p)];
                 // Attempt to pull the int64 directly
                 const int64_t* int64Value = std::get_if<int64_t>(&valueVariant);
 
@@ -566,11 +566,11 @@
                 temp = temp * std::pow(10, scaleMultiplier);
                 if (forceToInt)
                 {
-                    valueIt = static_cast<int64_t>(temp);
+                    jValueIt = static_cast<int64_t>(temp);
                 }
                 else
                 {
-                    valueIt = temp;
+                    jValueIt = temp;
                 }
             }
         }
@@ -985,7 +985,7 @@
  */
 void setSensorOverride(crow::Response& res, const crow::Request& req,
                        const std::vector<std::string>& params,
-                       const std::initializer_list<const char*> typeList,
+                       const std::vector<const char*> typeList,
                        const std::string& chassisSubNode)
 {
 
diff --git a/redfish-core/lib/thermal.hpp b/redfish-core/lib/thermal.hpp
index f266c40..58e7cd4 100644
--- a/redfish-core/lib/thermal.hpp
+++ b/redfish-core/lib/thermal.hpp
@@ -37,7 +37,7 @@
     }
 
   private:
-    std::initializer_list<const char*> typeList = {
+    std::vector<const char*> typeList = {
         "/xyz/openbmc_project/sensors/fan_tach",
         "/xyz/openbmc_project/sensors/temperature",
         "/xyz/openbmc_project/sensors/fan_pwm"};