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/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)))
{