Merge topic 'nullptr'

7b0a629693 Source: use C++11 nullptr

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !8207
This commit is contained in:
Brad King
2023-02-15 13:16:45 +00:00
committed by Kitware Robot
10 changed files with 51 additions and 49 deletions

View File

@@ -263,7 +263,7 @@ cmGeneratedFileStream& operator<<(cmGeneratedFileStream& s,
}
// Look up variable; if no value is set, returns an empty string;
// basically a wrapper that handles the NULL-ptr return from GetOption().
// basically a wrapper that handles the nullptr return from GetOption().
std::string cmCPackFreeBSDGenerator::var_lookup(const char* var_name)
{
cmValue pv = this->GetOption(var_name);
@@ -402,7 +402,7 @@ int cmCPackFreeBSDGenerator::PackageFiles()
this->packageFileNames.emplace_back(actualPackage);
}
if (!pkg_initialized() && pkg_init(NULL, NULL) != EPKG_OK) {
if (!pkg_initialized() && pkg_init(nullptr, nullptr) != EPKG_OK) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Can not initialize FreeBSD libpkg." << std::endl);
return 0;

View File

@@ -157,7 +157,7 @@ bool cmCTestCurl::UploadFile(std::string const& local_file,
// Now run off and do what you've been told!
::curl_easy_perform(this->Curl);
::fclose(ftpfile);
::curl_easy_setopt(this->Curl, CURLOPT_HTTPHEADER, NULL);
::curl_easy_setopt(this->Curl, CURLOPT_HTTPHEADER, nullptr);
::curl_slist_free_all(headers);
if (!responseData.empty()) {

View File

@@ -406,7 +406,7 @@ static bool DumpFile(std::string const& nmPath, const char* filename,
LPVOID lpFileBase;
hFile = CreateFileW(cmsys::Encoding::ToWide(filename).c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
if (hFile == INVALID_HANDLE_VALUE) {
@@ -414,7 +414,8 @@ static bool DumpFile(std::string const& nmPath, const char* filename,
return false;
}
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
hFileMapping =
CreateFileMapping(hFile, nullptr, PAGE_READONLY, 0, 0, nullptr);
if (hFileMapping == 0) {
CloseHandle(hFile);
fprintf(stderr, "Couldn't open file mapping with CreateFileMapping()\n");

View File

@@ -131,12 +131,12 @@ std::string cmCurlFixFileURL(std::string url)
// Convert string from UTF-8 to ACP if this is a file:// URL.
std::wstring wurl = cmsys::Encoding::ToWide(url);
if (!wurl.empty()) {
int mblen =
WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, NULL, 0, NULL, NULL);
int mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, nullptr, 0,
nullptr, nullptr);
if (mblen > 0) {
std::vector<char> chars(mblen);
mblen = WideCharToMultiByte(CP_ACP, 0, wurl.c_str(), -1, &chars[0],
mblen, NULL, NULL);
mblen, nullptr, nullptr);
if (mblen > 0) {
url = &chars[0];
}

View File

@@ -56,9 +56,9 @@ std::string cmFileLockResult::GetOutputMessage() const
# define WINMSG_BUF_LEN (1024)
char winmsg[WINMSG_BUF_LEN];
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
if (FormatMessageA(flags, NULL, this->ErrorValue,
if (FormatMessageA(flags, nullptr, this->ErrorValue,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)winmsg, WINMSG_BUF_LEN, NULL)) {
(LPSTR)winmsg, WINMSG_BUF_LEN, nullptr)) {
const std::string message = winmsg;
return message;
} else {

View File

@@ -36,9 +36,9 @@ cmFileLockResult cmFileLock::OpenFile()
{
const DWORD access = GENERIC_READ | GENERIC_WRITE;
const DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
const PSECURITY_ATTRIBUTES security = NULL;
const PSECURITY_ATTRIBUTES security = nullptr;
const DWORD attr = 0;
const HANDLE templ = NULL;
const HANDLE templ = nullptr;
this->File = CreateFileW(
cmSystemTools::ConvertToWindowsExtendedPath(this->Filename).c_str(),
access, shareMode, security, OPEN_EXISTING, attr, templ);

View File

@@ -544,12 +544,12 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
cmSystemTools::ConvertToUnixSlashes(s1);
std::string keyname;
HKEY hkey = NULL;
HKEY hkey = nullptr;
LONG result = ERROR_SUCCESS;
DWORD index = 0;
keyname = regKeyBase + "\\OtherProjects7";
hkey = NULL;
hkey = nullptr;
result =
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
0, KEY_READ, &hkey);
@@ -567,7 +567,7 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
RegEnumKeyExW(hkey, index, subkeyname, &cch_subkeyname, 0, keyclass,
&cch_keyclass, &lastWriteTime)) {
// Open the subkey and query the values of interest:
HKEY hsubkey = NULL;
HKEY hsubkey = nullptr;
result = RegOpenKeyExW(hkey, subkeyname, 0, KEY_READ, &hsubkey);
if (ERROR_SUCCESS == result) {
DWORD valueType = REG_SZ;
@@ -641,7 +641,7 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
nextAvailableSubKeyName = std::to_string(index);
keyname = regKeyBase + "\\RecordingProject7";
hkey = NULL;
hkey = nullptr;
result =
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
0, KEY_READ, &hkey);
@@ -687,13 +687,13 @@ void WriteVSMacrosFileRegistryEntry(const std::string& nextAvailableSubKeyName,
const std::string& regKeyBase)
{
std::string keyname = regKeyBase + "\\OtherProjects7";
HKEY hkey = NULL;
HKEY hkey = nullptr;
LONG result =
RegOpenKeyExW(HKEY_CURRENT_USER, cmsys::Encoding::ToWide(keyname).c_str(),
0, KEY_READ | KEY_WRITE, &hkey);
if (ERROR_SUCCESS == result) {
// Create the subkey and set the values of interest:
HKEY hsubkey = NULL;
HKEY hsubkey = nullptr;
wchar_t lpClass[] = L"";
result = RegCreateKeyExW(
hkey, cmsys::Encoding::ToWide(nextAvailableSubKeyName).c_str(), 0,
@@ -960,13 +960,13 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
static bool OpenSolution(std::string const& sln)
{
HRESULT comInitialized =
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (FAILED(comInitialized)) {
return false;
}
HINSTANCE hi =
ShellExecuteA(NULL, "open", sln.c_str(), NULL, NULL, SW_SHOWNORMAL);
HINSTANCE hi = ShellExecuteA(nullptr, "open", sln.c_str(), nullptr, nullptr,
SW_SHOWNORMAL);
CoUninitialize();

View File

@@ -85,7 +85,7 @@ bool cmProcessOutput::DecodeText(std::string raw, std::string& decoded,
rawparts[id - 1] += *(raw.end() - 1);
raw.resize(raw.size() - 1);
}
success = DoDecodeText(raw, decoded, NULL);
success = DoDecodeText(raw, decoded, nullptr);
} else {
bool restoreDecoded = false;
std::string firstDecoded = decoded;
@@ -114,7 +114,7 @@ bool cmProcessOutput::DecodeText(std::string raw, std::string& decoded,
}
}
} else {
success = DoDecodeText(raw, decoded, NULL);
success = DoDecodeText(raw, decoded, nullptr);
}
}
return success;
@@ -143,7 +143,7 @@ bool cmProcessOutput::DoDecodeText(std::string raw, std::string& decoded,
{
bool success = false;
const int wlength =
MultiByteToWideChar(codepage, 0, raw.c_str(), int(raw.size()), NULL, 0);
MultiByteToWideChar(codepage, 0, raw.c_str(), int(raw.size()), nullptr, 0);
auto wdata = cm::make_unique<wchar_t[]>(wlength);
int r = MultiByteToWideChar(codepage, 0, raw.c_str(), int(raw.size()),
wdata.get(), wlength);
@@ -156,10 +156,10 @@ bool cmProcessOutput::DoDecodeText(std::string raw, std::string& decoded,
}
}
int length = WideCharToMultiByte(defaultCodepage, 0, wdata.get(), wlength,
NULL, 0, NULL, NULL);
nullptr, 0, nullptr, nullptr);
auto data = cm::make_unique<char[]>(length);
r = WideCharToMultiByte(defaultCodepage, 0, wdata.get(), wlength,
data.get(), length, NULL, NULL);
data.get(), length, nullptr, nullptr);
if (r > 0) {
decoded = std::string(data.get(), length);
success = true;

View File

@@ -956,7 +956,7 @@ std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
// uv_fs_realpath uses Windows Vista API so fallback to kwsys if not found
std::string resolved_path;
uv_fs_t req;
int err = uv_fs_realpath(NULL, &req, path.c_str(), NULL);
int err = uv_fs_realpath(nullptr, &req, path.c_str(), nullptr);
if (!err) {
resolved_path = std::string((char*)req.ptr);
cmSystemTools::ConvertToUnixSlashes(resolved_path);
@@ -967,12 +967,12 @@ std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
} else if (err == UV_ENOSYS) {
resolved_path = cmsys::SystemTools::GetRealPath(path, errorMessage);
} else if (errorMessage) {
LPSTR message = NULL;
LPSTR message = nullptr;
DWORD size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&message, 0,
NULL);
nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&message,
0, nullptr);
*errorMessage = std::string(message, size);
LocalFree(message);
@@ -1329,32 +1329,33 @@ std::string cmSystemTools::ComputeCertificateThumbprint(
std::string thumbprint;
CRYPT_INTEGER_BLOB cryptBlob;
HCERTSTORE certStore = NULL;
PCCERT_CONTEXT certContext = NULL;
HCERTSTORE certStore = nullptr;
PCCERT_CONTEXT certContext = nullptr;
HANDLE certFile = CreateFileW(
cmsys::Encoding::ToWide(source.c_str()).c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (certFile != INVALID_HANDLE_VALUE && certFile != NULL) {
DWORD fileSize = GetFileSize(certFile, NULL);
if (certFile != INVALID_HANDLE_VALUE && certFile != nullptr) {
DWORD fileSize = GetFileSize(certFile, nullptr);
if (fileSize != INVALID_FILE_SIZE) {
auto certData = cm::make_unique<BYTE[]>(fileSize);
if (certData != NULL) {
if (certData != nullptr) {
DWORD dwRead = 0;
if (ReadFile(certFile, certData.get(), fileSize, &dwRead, NULL)) {
if (ReadFile(certFile, certData.get(), fileSize, &dwRead, nullptr)) {
cryptBlob.cbData = fileSize;
cryptBlob.pbData = certData.get();
// Verify that this is a valid cert
if (PFXIsPFXBlob(&cryptBlob)) {
// Open the certificate as a store
certStore = PFXImportCertStore(&cryptBlob, NULL, CRYPT_EXPORTABLE);
if (certStore != NULL) {
certStore =
PFXImportCertStore(&cryptBlob, nullptr, CRYPT_EXPORTABLE);
if (certStore != nullptr) {
// There should only be 1 cert.
certContext =
CertEnumCertificatesInStore(certStore, certContext);
if (certContext != NULL) {
if (certContext != nullptr) {
// The hash is 20 bytes
BYTE hashData[20];
DWORD hashLength = 20;
@@ -2375,22 +2376,22 @@ static void EnsureStdPipe(DWORD fd)
}
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.lpSecurityDescriptor = nullptr;
sa.bInheritHandle = TRUE;
HANDLE h = CreateFileW(
L"NUL",
fd == STD_INPUT_HANDLE ? FILE_GENERIC_READ
: FILE_GENERIC_WRITE | FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, OPEN_EXISTING, 0, NULL);
FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, OPEN_EXISTING, 0, nullptr);
if (h == INVALID_HANDLE_VALUE) {
LPSTR message = NULL;
LPSTR message = nullptr;
DWORD size = FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&message, 0, NULL);
nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&message, 0, nullptr);
std::string msg = std::string(message, size);
LocalFree(message);
std::cerr << "failed to open NUL for missing stdio pipe: " << msg;
@@ -2535,10 +2536,10 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
#if defined(_WIN32) && !defined(__CYGWIN__)
(void)argv0; // ignore this on windows
wchar_t modulepath[_MAX_PATH];
::GetModuleFileNameW(NULL, modulepath, sizeof(modulepath));
::GetModuleFileNameW(nullptr, modulepath, sizeof(modulepath));
std::string path = cmsys::Encoding::ToNarrow(modulepath);
std::string realPath =
cmSystemTools::GetRealPathResolvingWindowsSubst(path, NULL);
cmSystemTools::GetRealPathResolvingWindowsSubst(path, nullptr);
if (realPath.empty()) {
realPath = path;
}

View File

@@ -171,7 +171,7 @@ std::codecvt_base::result codecvt::Decode(mbstate_t& state, int size,
}
int tlen = WideCharToMultiByte(m_codepage, 0, wbuf, wlen, to_next,
to_end - to_next, NULL, NULL);
to_end - to_next, nullptr, nullptr);
if (tlen <= 0) {
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
return std::codecvt_base::partial;
@@ -206,7 +206,7 @@ std::codecvt_base::result codecvt::DecodePartial(mbstate_t& state,
}
int tlen = WideCharToMultiByte(m_codepage, 0, wbuf, wlen, to_next,
to_end - to_next, NULL, NULL);
to_end - to_next, nullptr, nullptr);
if (tlen <= 0) {
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
return std::codecvt_base::partial;