Enable cppcoreguidelines-init-variables

We try to enforce this rule, but clearly the robot can do a better job.
Enable the rule, and for init of all variables that clang-tidy finds in
error.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Icf64bc51b3180de29f7e92fa5c5f636e6b1462a6
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 1fac7dd..fd61680 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -108,7 +108,7 @@
                 const std::pair<
                     std::string,
                     boost::container::flat_map<std::string, BasicVariantType>>*
-                    baseConfiguration;
+                    baseConfiguration = nullptr;
                 for (const std::pair<sdbusplus::message::object_path,
                                      SensorData>& sensor : sensorConfigurations)
                 {
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index d57d565..078d790 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -43,20 +43,19 @@
     Sensor(escapeName(sensorName), std::move(thresholdsIn), sensorConfiguration,
            objectType, false, false, 0, 0, conn, PowerState::on),
     std::enable_shared_from_this<CPUSensor>(), objServer(objectServer),
-    inputDev(io), waitTimer(io), path(path),
+    inputDev(io), waitTimer(io),
+    nameTcontrol("Tcontrol CPU" + std::to_string(cpuId)), path(path),
     privTcontrol(std::numeric_limits<double>::quiet_NaN()),
     dtsOffset(dtsOffset), show(show), pollTime(CPUSensor::sensorPollMs),
     minMaxReadCounter(0)
 {
-    nameTcontrol = labelTcontrol;
-    nameTcontrol += " CPU" + std::to_string(cpuId);
     if (show)
     {
         if (auto fileParts = splitFileName(path))
         {
             auto& [type, nr, item] = *fileParts;
             std::string interfacePath;
-            const char* units;
+            const char* units = nullptr;
             if (type.compare("power") == 0)
             {
                 interfacePath = "/xyz/openbmc_project/sensors/power/" + name;
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index 9e991e7..1c5574b 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -468,15 +468,17 @@
             std::exit(EXIT_FAILURE);
         }
 
-        State newState;
-        struct peci_ping_msg msg;
+        State newState = State::OFF;
+        struct peci_ping_msg msg
+        {};
         msg.addr = config.addr;
         if (!ioctl(file, PECI_IOC_PING, &msg))
         {
             bool dimmReady = false;
             for (unsigned int rank = 0; rank < rankNumMax; rank++)
             {
-                struct peci_rd_pkg_cfg_msg msg;
+                struct peci_rd_pkg_cfg_msg msg
+                {};
                 msg.addr = config.addr;
                 msg.index = PECI_MBX_INDEX_DDR_DIMM_TEMP;
                 msg.param = rank;
@@ -505,10 +507,6 @@
                 newState = State::ON;
             }
         }
-        else
-        {
-            newState = State::OFF;
-        }
 
         close(file);
 
diff --git a/src/ExternalSensorMain.cpp b/src/ExternalSensorMain.cpp
index 1ced726..477a4c6 100644
--- a/src/ExternalSensorMain.cpp
+++ b/src/ExternalSensorMain.cpp
@@ -185,9 +185,6 @@
                 const SensorBaseConfigMap& baseConfigMap =
                     baseConfiguration.second;
 
-                double minValue;
-                double maxValue;
-
                 // MinValue and MinValue are mandatory numeric parameters
                 auto minFound = baseConfigMap.find("MinValue");
                 if (minFound == baseConfigMap.end())
@@ -196,7 +193,7 @@
                               << interfacePath << "\n";
                     continue;
                 }
-                minValue =
+                double minValue =
                     std::visit(VariantToDoubleVisitor(), minFound->second);
                 if (!std::isfinite(minValue))
                 {
@@ -212,7 +209,7 @@
                               << interfacePath << "\n";
                     continue;
                 }
-                maxValue =
+                double maxValue =
                     std::visit(VariantToDoubleVisitor(), maxFound->second);
                 if (!std::isfinite(maxValue))
                 {
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 786498c..a32d054 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -188,7 +188,7 @@
                 // convert to 0 based
                 size_t index = std::stoul(indexStr) - 1;
 
-                const char* baseType;
+                const char* baseType = nullptr;
                 const SensorData* sensorData = nullptr;
                 const std::string* interfacePath = nullptr;
                 const SensorBaseConfiguration* baseConfiguration = nullptr;
diff --git a/src/IpmbSensor.cpp b/src/IpmbSensor.cpp
index b2c9dd2..7c76d3b 100644
--- a/src/IpmbSensor.cpp
+++ b/src/IpmbSensor.cpp
@@ -188,11 +188,11 @@
     else if (type == IpmbType::ADM1278HSC)
     {
         commandAddress = meAddress;
+        uint8_t snsNum = 0;
         switch (subType)
         {
             case IpmbSubType::temp:
             case IpmbSubType::curr:
-                uint8_t snsNum;
                 if (subType == IpmbSubType::temp)
                 {
                     snsNum = 0x8d;
diff --git a/src/MCUTempSensor.cpp b/src/MCUTempSensor.cpp
index 79a2959..e9a84fa 100644
--- a/src/MCUTempSensor.cpp
+++ b/src/MCUTempSensor.cpp
@@ -162,7 +162,7 @@
             std::cerr << "timer error\n";
             return;
         }
-        int16_t temp;
+        int16_t temp = 0;
         int ret = getMCURegsInfoWord(tempReg, &temp);
         if (ret >= 0)
         {
diff --git a/src/NVMeBasicContext.cpp b/src/NVMeBasicContext.cpp
index c828d27..ea17c73 100644
--- a/src/NVMeBasicContext.cpp
+++ b/src/NVMeBasicContext.cpp
@@ -50,7 +50,7 @@
 static void decodeBasicQuery(const std::array<uint8_t, 6>& req, int& bus,
                              uint8_t& device, uint8_t& offset)
 {
-    uint32_t busle;
+    uint32_t busle = 0;
 
     memcpy(&busle, req.data(), sizeof(busle));
     bus = le32toh(busle);
@@ -61,20 +61,21 @@
 static ssize_t execBasicQuery(int bus, uint8_t addr, uint8_t cmd,
                               std::vector<uint8_t>& resp)
 {
-    char devpath[PATH_MAX]{};
-    int32_t size;
+    std::array<char, PATH_MAX> devpath{};
+    int32_t size = 0;
 
-    ssize_t rc = snprintf(devpath, sizeof(devpath), "/dev/i2c-%" PRIu32, bus);
+    ssize_t rc =
+        snprintf(devpath.data(), devpath.size(), "/dev/i2c-%" PRIu32, bus);
     if ((size_t)rc > sizeof(devpath))
     {
         std::cerr << "Failed to format device path for bus " << bus << "\n";
         return -EINVAL;
     }
 
-    int dev = ::open(devpath, O_RDWR);
+    int dev = ::open(devpath.data(), O_RDWR);
     if (dev == -1)
     {
-        std::cerr << "Failed to open bus device " << devpath << ": "
+        std::cerr << "Failed to open bus device " << devpath.data() << ": "
                   << strerror(errno) << "\n";
         return -errno;
     }
@@ -126,14 +127,14 @@
 static ssize_t processBasicQueryStream(int in, int out)
 {
     std::vector<uint8_t> resp{};
-    ssize_t rc;
+    ssize_t rc = 0;
 
     while (true)
     {
-        uint8_t device;
-        uint8_t offset;
-        uint8_t len;
-        int bus;
+        uint8_t device = 0;
+        uint8_t offset = 0;
+        uint8_t len = 0;
+        int bus = 0;
 
         /* bus + address + command */
         std::array<uint8_t, sizeof(uint32_t) + 1 + 1> req{};
@@ -189,9 +190,8 @@
         uint8_t* cursor = resp.data();
         while (len > 0)
         {
-            ssize_t egress;
-
-            if ((egress = ::write(out, cursor, len)) == -1)
+            ssize_t egress = ::write(out, cursor, len);
+            if (egress == -1)
             {
                 rc = -errno;
                 std::cerr << "Failed to write block data of length " << std::dec
@@ -225,8 +225,8 @@
 NVMeBasicContext::NVMeBasicContext(boost::asio::io_service& io, int rootBus) :
     NVMeContext::NVMeContext(io, rootBus), io(io), reqStream(io), respStream(io)
 {
-    std::array<int, 2> responsePipe;
-    std::array<int, 2> requestPipe;
+    std::array<int, 2> responsePipe{};
+    std::array<int, 2> requestPipe{};
 
     /* Set up inter-thread communication */
     if (::pipe(requestPipe.data()) == -1)
@@ -262,12 +262,12 @@
     respStream.assign(responsePipe[0]);
 
     std::thread thread([streamIn, streamOut]() {
-        ssize_t rc;
+        ssize_t rc = 0;
 
         if ((rc = processBasicQueryStream(streamIn, streamOut)) < 0)
         {
             std::cerr << "Failure while processing query stream: "
-                      << strerror(-rc) << "\n";
+                      << strerror(static_cast<int>(-rc)) << "\n";
         }
 
         if (::close(streamIn) == -1)
diff --git a/src/PSUSensorMain.cpp b/src/PSUSensorMain.cpp
index ae7afc3..28d37ff 100644
--- a/src/PSUSensorMain.cpp
+++ b/src/PSUSensorMain.cpp
@@ -324,7 +324,6 @@
             continue;
         }
 
-        const std::string* psuName;
         auto directory = pmbusPath.parent_path();
 
         auto ret = directories.insert(directory.string());
@@ -399,10 +398,9 @@
                 continue;
             }
 
-            const uint64_t* confBus;
-            const uint64_t* confAddr;
-            if (!(confBus = std::get_if<uint64_t>(&(configBus->second))) ||
-                !(confAddr = std::get_if<uint64_t>(&(configAddress->second))))
+            const uint64_t* confBus = std::get_if<uint64_t>(&(configBus->second));
+            const uint64_t* confAddr = std::get_if<uint64_t>(&(configAddress->second));
+            if (confBus == nullptr || confAddr == nullptr)
             {
                 std::cerr
                     << "Cannot get bus or address, invalid configuration\n";
@@ -442,8 +440,8 @@
                       << deviceName << "\n";
             continue;
         }
-
-        if (!(psuName = std::get_if<std::string>(&(findPSUName->second))))
+        const std::string* psuName = std::get_if<std::string>(&(findPSUName->second));
+        if (psuName == nullptr)
         {
             std::cerr << "Cannot find psu name, invalid configuration\n";
             continue;