Modernize use nullptr
NULL => nullptr as per modernize-use-nullptr.
After this change:
```
grep "NULL" -r */*.*pp *.*pp
None
```
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: Iecddab6fba06f959866048eff4496310453d0fde
diff --git a/argument.cpp b/argument.cpp
index 38d3978..35f33e3 100644
--- a/argument.cpp
+++ b/argument.cpp
@@ -29,7 +29,8 @@
ArgumentParser::ArgumentParser(int argc, char** argv)
{
auto option = 0;
- while (-1 != (option = getopt_long(argc, argv, optionstr, options, NULL)))
+ while (-1 !=
+ (option = getopt_long(argc, argv, optionstr, options, nullptr)))
{
if ((option == '?') || (option == 'h'))
{
diff --git a/certificate.cpp b/certificate.cpp
index 0e19141..88ff65e 100644
--- a/certificate.cpp
+++ b/certificate.cpp
@@ -90,8 +90,8 @@
std::string
Certificate::generateUniqueFilePath(const std::string& directoryPath)
{
- char* filePath = tempnam(directoryPath.c_str(), NULL);
- if (filePath == NULL)
+ char* filePath = tempnam(directoryPath.c_str(), nullptr);
+ if (filePath == nullptr)
{
log<level::ERR>(
"Error occurred while creating random certificate file path",
@@ -293,8 +293,8 @@
elog<InternalFailure>();
}
- errCode =
- X509_STORE_CTX_init(storeCtx.get(), x509Store.get(), cert.get(), NULL);
+ errCode = X509_STORE_CTX_init(storeCtx.get(), x509Store.get(), cert.get(),
+ nullptr);
if (errCode != 1)
{
log<level::ERR>("Error occurred during X509_STORE_CTX_init call",
@@ -526,7 +526,7 @@
// Go through each usage in the bit string and convert to
// corresponding string value
if ((usage = static_cast<ASN1_BIT_STRING*>(
- X509_get_ext_d2i(cert.get(), NID_key_usage, NULL, NULL))))
+ X509_get_ext_d2i(cert.get(), NID_key_usage, nullptr, nullptr))))
{
for (auto i = 0; i < usage->length; ++i)
{
@@ -542,8 +542,8 @@
}
EXTENDED_KEY_USAGE* extUsage;
- if ((extUsage = static_cast<EXTENDED_KEY_USAGE*>(
- X509_get_ext_d2i(cert.get(), NID_ext_key_usage, NULL, NULL))))
+ if ((extUsage = static_cast<EXTENDED_KEY_USAGE*>(X509_get_ext_d2i(
+ cert.get(), NID_ext_key_usage, nullptr, nullptr))))
{
for (int i = 0; i < sk_ASN1_OBJECT_num(extUsage); i++)
{
diff --git a/certs_manager.cpp b/certs_manager.cpp
index 0303c9a..6aca6af 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -306,7 +306,7 @@
}
// Block SIGCHLD first, so that the event loop can handle it
- if (sigprocmask(SIG_BLOCK, &ss, NULL) < 0)
+ if (sigprocmask(SIG_BLOCK, &ss, nullptr) < 0)
{
log<level::ERR>("Unable to block signal");
elog<InternalFailure>();
@@ -470,7 +470,7 @@
}
RSA* rsa = RSA_new();
- ret = RSA_generate_key_ex(rsa, keyBitLen, bne.get(), NULL);
+ ret = RSA_generate_key_ex(rsa, keyBitLen, bne.get(), nullptr);
if (ret != 1)
{
free(rsa);
@@ -546,7 +546,7 @@
EC_KEY* ecKey = EC_KEY_new_by_curve_name(ecGrp);
- if (ecKey == NULL)
+ if (ecKey == nullptr)
{
log<level::ERR>(
"Error occurred during create the EC_Key object from NID",
@@ -638,12 +638,13 @@
fs::path privKeyPath = certParentInstallPath / privKeyFileName;
FILE* fp = std::fopen(privKeyPath.c_str(), "w");
- if (fp == NULL)
+ if (fp == nullptr)
{
log<level::ERR>("Error occurred creating private key file");
elog<InternalFailure>();
}
- int ret = PEM_write_PrivateKey(fp, pKey.get(), NULL, NULL, 0, 0, NULL);
+ int ret =
+ PEM_write_PrivateKey(fp, pKey.get(), nullptr, nullptr, 0, 0, nullptr);
std::fclose(fp);
if (ret == 0)
{
@@ -695,9 +696,9 @@
}
}
- FILE* fp = NULL;
+ FILE* fp = nullptr;
- if ((fp = std::fopen(filePath.c_str(), "w")) == NULL)
+ if ((fp = std::fopen(filePath.c_str(), "w")) == nullptr)
{
log<level::ERR>("Error opening the file to write the CSR",
entry("FILENAME=%s", filePath.c_str()));
diff --git a/csr.cpp b/csr.cpp
index c93a487..cf74f53 100644
--- a/csr.cpp
+++ b/csr.cpp
@@ -49,11 +49,11 @@
}
FILE* fp = std::fopen(csrFilePath.c_str(), "r");
- X509_REQ_Ptr x509Req(PEM_read_X509_REQ(fp, NULL, NULL, NULL),
+ X509_REQ_Ptr x509Req(PEM_read_X509_REQ(fp, nullptr, nullptr, nullptr),
::X509_REQ_free);
- if (x509Req == NULL || fp == NULL)
+ if (x509Req == nullptr || fp == nullptr)
{
- if (fp != NULL)
+ if (fp != nullptr)
{
std::fclose(fp);
}
@@ -71,7 +71,7 @@
elog<InternalFailure>();
}
- BUF_MEM* mem = NULL;
+ BUF_MEM* mem = nullptr;
BIO_get_mem_ptr(bio.get(), &mem);
std::string pem(mem->data, mem->length);
return pem;
diff --git a/test/certs_manager_test.cpp b/test/certs_manager_test.cpp
index c0c712c..38c563a 100644
--- a/test/certs_manager_test.cpp
+++ b/test/certs_manager_test.cpp
@@ -40,7 +40,7 @@
{
char dirTemplate[] = "/tmp/FakeCerts.XXXXXX";
auto dirPtr = mkdtemp(dirTemplate);
- if (dirPtr == NULL)
+ if (dirPtr == nullptr)
{
throw std::bad_alloc();
}
@@ -791,7 +791,7 @@
{
char dirTemplate[] = "/tmp/FakeCerts.XXXXXX";
auto dirPtr = mkdtemp(dirTemplate);
- if (dirPtr == NULL)
+ if (dirPtr == nullptr)
{
throw std::bad_alloc();
}