clang-tidy: Replace NULL with nullptr

Replaced all instances of NULL with nullptr to improve type safety
and clarity, as nullptr is the modern C++ standard for null pointers.

Tested: Build verified

Change-Id: Ia40d9435ab57651ec6d13d5408cf69130043fa79
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/groupext.cpp b/groupext.cpp
index 222ce9a..f61bf1f 100644
--- a/groupext.cpp
+++ b/groupext.cpp
@@ -24,7 +24,7 @@
 void registerNetFnGroupExtFunctions()
 {
     // <Group Extension Command>
-    ipmi_register_callback(NETFUN_GRPEXT, GRPEXT_GET_GROUP_CMD, NULL,
+    ipmi_register_callback(NETFUN_GRPEXT, GRPEXT_GET_GROUP_CMD, nullptr,
                            ipmi_groupext, PRIVILEGE_USER);
 
     return;
diff --git a/include/ipmid/handler.hpp b/include/ipmid/handler.hpp
index 4337b17..c3d5f91 100644
--- a/include/ipmid/handler.hpp
+++ b/include/ipmid/handler.hpp
@@ -90,8 +90,8 @@
 static inline const char* currentExceptionType()
 {
     int status;
-    return abi::__cxa_demangle(abi::__cxa_current_exception_type()->name(), 0,
-                               0, &status);
+    return abi::__cxa_demangle(abi::__cxa_current_exception_type()->name(),
+                               nullptr, nullptr, &status);
 }
 
 /**
diff --git a/ipmisensor.cpp b/ipmisensor.cpp
index 55e4914..b66c585 100644
--- a/ipmisensor.cpp
+++ b/ipmisensor.cpp
@@ -244,7 +244,7 @@
     {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""},
     {0xCA, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""},
     {0xCA, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""},
-    {0xFF, 0xFF, NULL, "", "", ""}};
+    {0xFF, 0xFF, nullptr, "", "", ""}};
 
 void reportSensorEventAssert(const sensorRES_t* pRec, int index)
 {
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index e40fa49..134eaa6 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -269,7 +269,7 @@
     dbus_interface_t a;
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
-    sd_bus_message* m = NULL;
+    sd_bus_message* m = nullptr;
 
     r = find_openbmc_path(number, &a);
 
@@ -296,7 +296,7 @@
         goto final;
     }
 
-    r = sd_bus_call(bus, m, 0, &error, NULL);
+    r = sd_bus_call(bus, m, 0, &error, nullptr);
     if (r < 0)
     {
         std::fprintf(stderr, "Failed to call the method: %s", strerror(-r));
@@ -314,7 +314,7 @@
     dbus_interface_t a;
     int r;
     sd_bus_error error = SD_BUS_ERROR_NULL;
-    sd_bus_message* m = NULL;
+    sd_bus_message* m = nullptr;
 
     r = find_openbmc_path(number, &a);
 
@@ -341,7 +341,7 @@
         goto final;
     }
 
-    r = sd_bus_call(bus, m, 0, &error, NULL);
+    r = sd_bus_call(bus, m, 0, &error, nullptr);
     if (r < 0)
     {
         std::fprintf(stderr, "12 Failed to call the method: %s", strerror(-r));
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 5b8eb6d..d96f2d6 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -892,8 +892,8 @@
                           ipmiStorageGetSelTimeUtcOffset);
 
     // <Get SEL Entry>
-    ipmi_register_callback(NETFUN_STORAGE, ipmi::storage::cmdGetSelEntry, NULL,
-                           getSELEntry, PRIVILEGE_USER);
+    ipmi_register_callback(NETFUN_STORAGE, ipmi::storage::cmdGetSelEntry,
+                           nullptr, getSELEntry, PRIVILEGE_USER);
 
     // <Delete SEL Entry>
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
diff --git a/user_channel/channel_mgmt.cpp b/user_channel/channel_mgmt.cpp
index 0b76330..69958fa 100644
--- a/user_channel/channel_mgmt.cpp
+++ b/user_channel/channel_mgmt.cpp
@@ -952,7 +952,7 @@
             if (jsonChInfo[mediumTypeString].get<std::string>() == "lan-802.3")
             {
                 channelFound = false;
-                for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
+                for (ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next)
                 {
                     if (jsonChData[nameString].get<std::string>() ==
                         ifa->ifa_name)
diff --git a/user_channel/file.hpp b/user_channel/file.hpp
index 204cfef..5be3a18 100644
--- a/user_channel/file.hpp
+++ b/user_channel/file.hpp
@@ -18,7 +18,7 @@
 {
   private:
     /** @brief handler for operating on file */
-    FILE* fp = NULL;
+    FILE* fp = nullptr;
 
     /** @brief File name. Needed in the case where the temp
      *         needs to be removed
diff --git a/user_channel/passwd_mgr.cpp b/user_channel/passwd_mgr.cpp
index f712779..929a83c 100644
--- a/user_channel/passwd_mgr.cpp
+++ b/user_channel/passwd_mgr.cpp
@@ -146,9 +146,9 @@
     uint8_t* iv, size_t ivLen, uint8_t* inBytes, size_t inBytesLen,
     uint8_t* mac, size_t* macLen, unsigned char* outBytes, size_t* outBytesLen)
 {
-    if (cipher == NULL || key == NULL || iv == NULL || inBytes == NULL ||
-        outBytes == NULL || mac == NULL || inBytesLen == 0 ||
-        (size_t)EVP_CIPHER_key_length(cipher) > keyLen ||
+    if (cipher == nullptr || key == nullptr || iv == nullptr ||
+        inBytes == nullptr || outBytes == nullptr || mac == nullptr ||
+        inBytesLen == 0 || (size_t)EVP_CIPHER_key_length(cipher) > keyLen ||
         (size_t)EVP_CIPHER_iv_length(cipher) > ivLen)
     {
         lg2::debug("Error Invalid Inputs");
@@ -161,7 +161,7 @@
         std::array<uint8_t, EVP_MAX_MD_SIZE> calMac;
         size_t calMacLen = calMac.size();
         // calculate MAC for the encrypted message.
-        if (NULL ==
+        if (nullptr ==
             HMAC(EVP_sha256(), key, keyLen, inBytes, inBytesLen, calMac.data(),
                  reinterpret_cast<unsigned int*>(&calMacLen)))
         {
@@ -188,7 +188,7 @@
     EVP_CIPHER_CTX_set_padding(ctx.get(), 1);
 
     // Set key & IV
-    int retval = EVP_CipherInit_ex(ctx.get(), cipher, NULL, key, iv,
+    int retval = EVP_CipherInit_ex(ctx.get(), cipher, nullptr, key, iv,
                                    static_cast<int>(doEncrypt));
     if (!retval)
     {
@@ -222,8 +222,8 @@
     if (doEncrypt)
     {
         // Create MAC for the encrypted message
-        if (NULL == HMAC(EVP_sha256(), key, keyLen, outBytes, *outBytesLen, mac,
-                         reinterpret_cast<unsigned int*>(macLen)))
+        if (nullptr == HMAC(EVP_sha256(), key, keyLen, outBytes, *outBytesLen,
+                            mac, reinterpret_cast<unsigned int*>(macLen)))
         {
             lg2::debug("Failed to create authentication");
             return -EIO;
@@ -247,10 +247,10 @@
     {
         // populate the user list with password
         char* outPtr = dataBuf.data();
-        char* nToken = NULL;
+        char* nToken = nullptr;
         char* linePtr = strtok_r(outPtr, "\n", &nToken);
         size_t lineSize = 0;
-        while (linePtr != NULL)
+        while (linePtr != nullptr)
         {
             size_t userEPos = 0;
             SecureString lineStr(linePtr);
@@ -261,7 +261,7 @@
                     lineStr.substr(0, userEPos),
                     lineStr.substr(userEPos + 1, lineSize - (userEPos + 1)));
             }
-            linePtr = strtok_r(NULL, "\n", &nToken);
+            linePtr = strtok_r(nullptr, "\n", &nToken);
         }
     }
 
@@ -325,9 +325,9 @@
     // compute the key needed to decrypt
     std::array<uint8_t, EVP_MAX_KEY_LENGTH> key;
     auto keyLen = key.size();
-    if (NULL == HMAC(EVP_sha256(), keyBuff.data(), keyBuff.size(),
-                     input.data() + sizeof(*metaData), metaData->hashSize,
-                     key.data(), reinterpret_cast<unsigned int*>(&keyLen)))
+    if (nullptr == HMAC(EVP_sha256(), keyBuff.data(), keyBuff.size(),
+                        input.data() + sizeof(*metaData), metaData->hashSize,
+                        key.data(), reinterpret_cast<unsigned int*>(&keyLen)))
     {
         lg2::debug("Failed to create MAC for authentication");
         return -EIO;
@@ -389,9 +389,9 @@
     if (inBytesLen != 0)
     {
         char* outPtr = reinterpret_cast<char*>(dataBuf.data());
-        char* nToken = NULL;
+        char* nToken = nullptr;
         char* linePtr = strtok_r(outPtr, "\n", &nToken);
-        while (linePtr != NULL)
+        while (linePtr != nullptr)
         {
             size_t userEPos = 0;
 
@@ -417,7 +417,7 @@
                                                   "%s\n", lineStr.data());
                 }
             }
-            linePtr = strtok_r(NULL, "\n", &nToken);
+            linePtr = strtok_r(nullptr, "\n", &nToken);
         }
         inBytesLen = bytesWritten;
     }
@@ -470,7 +470,7 @@
     // By "true", remove it at exit if still there.
     // This is needed to cleanup the temp file at exception
     phosphor::user::File temp(fd, strTempFileName, "w", true);
-    if ((temp)() == NULL)
+    if ((temp)() == nullptr)
     {
         close(fd);
         lg2::debug("Error creating temp file");
@@ -501,7 +501,7 @@
         lg2::debug("Hash genertion failed, bailing out");
         return -EIO;
     }
-    if (NULL ==
+    if (nullptr ==
         HMAC(digest, keyBuff.data(), keyBuff.size(), hash.data(), hashLen,
              key.data(), reinterpret_cast<unsigned int*>(&keyLen)))
     {
diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp
index 3d9a82f..b5680e0 100644
--- a/user_channel/user_mgmt.cpp
+++ b/user_channel/user_mgmt.cpp
@@ -684,7 +684,7 @@
 {
     const struct pam_conv localConversation = {pamFunctionConversation,
                                                const_cast<char*>(password)};
-    pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start
+    pam_handle_t* localAuthHandle = nullptr; // this gets set by pam_start
 
     int retval =
         pam_start("passwd", username, &localConversation, &localAuthHandle);
@@ -710,7 +710,7 @@
     const struct pam_conv localConversation = {
         pamFunctionConversation, const_cast<char*>(password.data())};
 
-    pam_handle_t* localAuthHandle = NULL; // this gets set by pam_start
+    pam_handle_t* localAuthHandle = nullptr; // this gets set by pam_start
 
     if (pam_start("dropbear", username.data(), &localConversation,
                   &localAuthHandle) != PAM_SUCCESS)