From: Gunnar Beutner Date: Thu, 14 Dec 2017 14:37:20 +0000 (+0100) Subject: Replace a few more NULLs with nullptr X-Git-Tag: v2.9.0~291^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ad83886ac1607d40c65af80950a7a8c6a72bd67;p=icinga2 Replace a few more NULLs with nullptr --- diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 2dfe71541..95df3714b 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -258,7 +258,7 @@ static int Main(void) || command->GetImpersonationLevel() == ImpersonationLevel::ImpersonateRoot) { TCHAR szPath[MAX_PATH]; - if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath))) { + if (GetModuleFileName(nullptr, szPath, ARRAYSIZE(szPath))) { SHELLEXECUTEINFO sei = { sizeof(sei) }; sei.lpVerb = _T("runas"); sei.lpFile = "cmd.exe"; @@ -434,7 +434,7 @@ static int Main(void) if (!command || vm.count("help")) { if (!command) - CLICommand::ShowCommands(argc, argv, NULL); + CLICommand::ShowCommands(argc, argv, nullptr); std::cout << visibleDesc << std::endl << "Report bugs at " << std::endl @@ -477,7 +477,7 @@ static int Main(void) } if (getgid() != gr->gr_gid) { - if (!vm.count("reload-internal") && setgroups(0, NULL) < 0) { + if (!vm.count("reload-internal") && setgroups(0, nullptr) < 0) { Log(LogCritical, "cli") << "setgroups() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; Log(LogCritical, "cli") @@ -567,19 +567,16 @@ static int Main(void) #ifdef _WIN32 static int SetupService(bool install, int argc, char **argv) { - SC_HANDLE schSCManager = OpenSCManager( - NULL, - NULL, - SC_MANAGER_ALL_ACCESS); + SC_HANDLE schSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_ALL_ACCESS); - if (NULL == schSCManager) { + if (!schSCManager) { printf("OpenSCManager failed (%d)\n", GetLastError()); return 1; } TCHAR szPath[MAX_PATH]; - if (!GetModuleFileName(NULL, szPath, MAX_PATH)) { + if (!GetModuleFileName(nullptr, szPath, MAX_PATH)) { printf("Cannot install service (%d)\n", GetLastError()); return 1; } @@ -604,7 +601,7 @@ static int SetupService(bool install, int argc, char **argv) SC_HANDLE schService = OpenService(schSCManager, "icinga2", SERVICE_ALL_ACCESS); - if (schService != NULL) { + if (schService) { SERVICE_STATUS status; ControlService(schService, SERVICE_CONTROL_STOP, &status); @@ -634,13 +631,13 @@ static int SetupService(bool install, int argc, char **argv) SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, szArgs.CStr(), - NULL, - NULL, - NULL, + nullptr, + nullptr, + nullptr, scmUser.c_str(), - NULL); + nullptr); - if (schService == NULL) { + if (!schService) { printf("CreateService failed (%d)\n", GetLastError()); CloseServiceHandle(schSCManager); return 1; @@ -662,7 +659,7 @@ static int SetupService(bool install, int argc, char **argv) printf("Service uninstalled successfully\n"); } else { if (!ChangeServiceConfig(schService, SERVICE_NO_CHANGE, SERVICE_AUTO_START, - SERVICE_ERROR_NORMAL, szArgs.CStr(), NULL, NULL, NULL, scmUser.c_str(), NULL, NULL)) { + SERVICE_ERROR_NORMAL, szArgs.CStr(), nullptr, nullptr, nullptr, scmUser.c_str(), nullptr, nullptr)) { printf("ChangeServiceConfig failed (%d)\n", GetLastError()); CloseServiceHandle(schService); CloseServiceHandle(schSCManager); @@ -677,7 +674,7 @@ static int SetupService(bool install, int argc, char **argv) return 1; } - if (!StartService(schService, 0, NULL)) { + if (!StartService(schService, 0, nullptr)) { printf("StartService failed (%d)\n", GetLastError()); CloseServiceHandle(schService); CloseServiceHandle(schSCManager); @@ -743,7 +740,7 @@ static VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv) l_SvcStatus.dwServiceSpecificExitCode = 0; ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); - l_Job = CreateJobObject(NULL, NULL); + l_Job = CreateJobObject(nullptr, nullptr); for (;;) { LPSTR arg = argv[0]; @@ -765,7 +762,7 @@ static VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv) char *uargs = strdup(args.CStr()); - BOOL res = CreateProcess(NULL, uargs, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); + BOOL res = CreateProcess(nullptr, uargs, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi); free(uargs); @@ -847,7 +844,7 @@ int main(int argc, char **argv) if (argc > 1 && strcmp(argv[1], "--scm") == 0) { SERVICE_TABLE_ENTRY dispatchTable[] = { { "icinga2", ServiceMain }, - { NULL, NULL } + { nullptr, nullptr } }; StartServiceCtrlDispatcher(dispatchTable); diff --git a/icinga-installer/icinga-installer.cpp b/icinga-installer/icinga-installer.cpp index 455ff2831..91ca0d6bc 100644 --- a/icinga-installer/icinga-installer.cpp +++ b/icinga-installer/icinga-installer.cpp @@ -31,7 +31,7 @@ static std::string GetIcingaInstallPath(void) { char szFileName[MAX_PATH]; - if (!GetModuleFileName(NULL, szFileName, sizeof(szFileName))) + if (!GetModuleFileName(nullptr, szFileName, sizeof(szFileName))) return ""; if (!PathRemoveFileSpec(szFileName)) @@ -100,7 +100,7 @@ static bool PathExists(const std::string& path) static std::string GetIcingaDataPath(void) { char path[MAX_PATH]; - if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path))) + if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, path))) throw std::runtime_error("SHGetFolderPath failed"); return std::string(path) + "\\icinga2"; } @@ -133,7 +133,7 @@ static std::string GetNSISInstallPath(void) BYTE pvData[MAX_PATH]; DWORD cbData = sizeof(pvData) - 1; DWORD lType; - if (RegQueryValueEx(hKey, NULL, NULL, &lType, pvData, &cbData) == ERROR_SUCCESS && lType == REG_SZ) { + if (RegQueryValueEx(hKey, nullptr, nullptr, &lType, pvData, &cbData) == ERROR_SUCCESS && lType == REG_SZ) { pvData[cbData] = '\0'; return (char *)pvData; @@ -279,7 +279,7 @@ static int UninstallIcinga(void) */ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { - CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); + CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); //AllocConsole(); int rc; @@ -291,7 +291,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi } else if (strcmp(lpCmdLine, "upgrade-nsis") == 0) { rc = UpgradeNSIS(); } else { - MessageBox(NULL, "This application should only be run by the MSI installer package.", "Icinga 2 Installer", MB_ICONWARNING); + MessageBox(nullptr, "This application should only be run by the MSI installer package.", "Icinga 2 Installer", MB_ICONWARNING); rc = 1; } diff --git a/icinga-studio/icinga-studio.cpp b/icinga-studio/icinga-studio.cpp index 8bfe2e549..bd4cdc1fa 100644 --- a/icinga-studio/icinga-studio.cpp +++ b/icinga-studio/icinga-studio.cpp @@ -44,7 +44,7 @@ public: std::string url = wUrl.ToStdString(); - ConnectForm f(NULL, new Url(url)); + ConnectForm f(nullptr, new Url(url)); if (f.ShowModal() != wxID_OK) return false; @@ -56,7 +56,7 @@ public: pUrl = new Url(argv[1].ToStdString()); } - MainForm *m = new MainForm(NULL, pUrl); + MainForm *m = new MainForm(nullptr, pUrl); m->Show(); return true; diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 1c7a73041..790eae905 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -54,7 +54,7 @@ using namespace icinga; REGISTER_TYPE(Application); boost::signals2::signal Application::OnReopenLogs; -Application::Ptr Application::m_Instance = NULL; +Application::Ptr Application::m_Instance = nullptr; bool Application::m_ShuttingDown = false; bool Application::m_RequestRestart = false; bool Application::m_RequestReopenLogs = false; @@ -73,9 +73,9 @@ double Application::m_LastReloadFailed; */ void Application::OnConfigLoaded(void) { - m_PidFile = NULL; + m_PidFile = nullptr; - ASSERT(m_Instance == NULL); + ASSERT(m_Instance == nullptr); m_Instance = this; } @@ -115,7 +115,7 @@ void Application::Stop(bool runtimeRemoved) Application::~Application(void) { - m_Instance = NULL; + m_Instance = nullptr; } void Application::Exit(int rc) @@ -151,7 +151,7 @@ void Application::InitializeBase(void) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &sa, NULL); + sigaction(SIGPIPE, &sa, nullptr); #endif /* _WIN32 */ Loader::ExecuteDeferredInitializers(); @@ -276,7 +276,7 @@ void Application::SetResourceLimits(void) for (int i = 1; i < argc; i++) new_argv[i + 1] = argv[i]; - new_argv[argc + 1] = NULL; + new_argv[argc + 1] = nullptr; (void) execvp(new_argv[0], new_argv); perror("execvp"); @@ -465,7 +465,7 @@ String Application::GetExePath(const String& argv0) #ifndef _WIN32 char buffer[MAXPATHLEN]; - if (getcwd(buffer, sizeof(buffer)) == NULL) { + if (!getcwd(buffer, sizeof(buffer))) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("getcwd") << boost::errinfo_errno(errno)); @@ -488,7 +488,7 @@ String Application::GetExePath(const String& argv0) if (!foundSlash) { const char *pathEnv = getenv("PATH"); - if (pathEnv != NULL) { + if (pathEnv) { std::vector paths; boost::algorithm::split(paths, pathEnv, boost::is_any_of(":")); @@ -510,7 +510,7 @@ String Application::GetExePath(const String& argv0) } } - if (realpath(executablePath.CStr(), buffer) == NULL) { + if (!realpath(executablePath.CStr(), buffer)) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("realpath") << boost::errinfo_errno(errno) @@ -521,7 +521,7 @@ String Application::GetExePath(const String& argv0) #else /* _WIN32 */ char FullExePath[MAXPATHLEN]; - if (!GetModuleFileName(NULL, FullExePath, sizeof(FullExePath))) + if (!GetModuleFileName(nullptr, FullExePath, sizeof(FullExePath))) BOOST_THROW_EXCEPTION(win32_error() << boost::errinfo_api_function("GetModuleFileName") << errinfo_win32_error(GetLastError())); @@ -632,7 +632,7 @@ void Application::AttachDebugger(const String& filename, bool interactive) "gdb", "-p", my_pid_str, - NULL + nullptr }; argv = const_cast(uargv); } else { @@ -647,7 +647,7 @@ void Application::AttachDebugger(const String& filename, bool interactive) "detach", "-ex", "quit", - NULL + nullptr }; argv = const_cast(uargv); } @@ -685,7 +685,7 @@ void Application::SigIntTermHandler(int signum) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; - sigaction(signum, &sa, NULL); + sigaction(signum, &sa, nullptr); Application::Ptr instance = Application::GetInstance(); @@ -718,7 +718,7 @@ void Application::SigAbrtHandler(int) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; - sigaction(SIGABRT, &sa, NULL); + sigaction(SIGABRT, &sa, nullptr); #endif /* _WIN32 */ std::cerr << "Caught SIGABRT." << std::endl @@ -778,14 +778,14 @@ BOOL WINAPI Application::CtrlHandler(DWORD type) instance->RequestShutdown(); - SetConsoleCtrlHandler(NULL, FALSE); + SetConsoleCtrlHandler(nullptr, FALSE); return TRUE; } bool Application::IsProcessElevated(void) { BOOL fIsElevated = FALSE; DWORD dwError = ERROR_SUCCESS; - HANDLE hToken = NULL; + HANDLE hToken = nullptr; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) dwError = GetLastError(); @@ -801,13 +801,13 @@ bool Application::IsProcessElevated(void) { if (hToken) { CloseHandle(hToken); - hToken = NULL; + hToken = nullptr; } if (ERROR_SUCCESS != dwError) { - LPSTR mBuf = NULL; + LPSTR mBuf = nullptr; if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), mBuf, 0, NULL)) + nullptr, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), mBuf, 0, nullptr)) BOOST_THROW_EXCEPTION(std::runtime_error("Failed to format error message, last error was: " + dwError)); else BOOST_THROW_EXCEPTION(std::runtime_error(mBuf)); @@ -832,7 +832,7 @@ void Application::ExceptionHandler(void) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_DFL; - sigaction(SIGABRT, &sa, NULL); + sigaction(SIGABRT, &sa, nullptr); #endif /* _WIN32 */ String fname = GetCrashReportFilename(); @@ -937,7 +937,7 @@ void Application::InstallExceptionHandlers(void) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = &Application::SigAbrtHandler; - sigaction(SIGABRT, &sa, NULL); + sigaction(SIGABRT, &sa, nullptr); #else /* _WIN32 */ SetUnhandledExceptionFilter(&Application::SEHUnhandledExceptionFilter); #endif /* _WIN32 */ @@ -954,11 +954,11 @@ int Application::Run(void) struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = &Application::SigIntTermHandler; - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, nullptr); + sigaction(SIGTERM, &sa, nullptr); sa.sa_handler = &Application::SigUsr1Handler; - sigaction(SIGUSR1, &sa, NULL); + sigaction(SIGUSR1, &sa, nullptr); #else /* _WIN32 */ SetConsoleCtrlHandler(&Application::CtrlHandler, TRUE); #endif /* _WIN32 */ @@ -987,17 +987,17 @@ void Application::UpdatePidFile(const String& filename, pid_t pid) { ObjectLock olock(this); - if (m_PidFile != NULL) + if (m_PidFile) fclose(m_PidFile); /* There's just no sane way of getting a file descriptor for a * C++ ofstream which is why we're using FILEs here. */ m_PidFile = fopen(filename.CStr(), "r+"); - if (m_PidFile == NULL) + if (!m_PidFile) m_PidFile = fopen(filename.CStr(), "w"); - if (m_PidFile == NULL) { + if (!m_PidFile) { Log(LogCritical, "Application") << "Could not open PID file '" << filename << "'."; BOOST_THROW_EXCEPTION(std::runtime_error("Could not open PID file '" + filename + "'")); @@ -1042,8 +1042,7 @@ void Application::ClosePidFile(bool unlink) { ObjectLock olock(this); - if (m_PidFile != NULL) - { + if (m_PidFile) { if (unlink) { String pidpath = GetPidPath(); ::unlink(pidpath.CStr()); @@ -1052,7 +1051,7 @@ void Application::ClosePidFile(bool unlink) fclose(m_PidFile); } - m_PidFile = NULL; + m_PidFile = nullptr; } /** @@ -1065,7 +1064,7 @@ pid_t Application::ReadPidFile(const String& filename) { FILE *pidfile = fopen(filename.CStr(), "r"); - if (pidfile == NULL) + if (!pidfile) return 0; #ifndef _WIN32 diff --git a/lib/base/context.cpp b/lib/base/context.cpp index 98abfec4e..dce0bf9b2 100644 --- a/lib/base/context.cpp +++ b/lib/base/context.cpp @@ -36,7 +36,7 @@ ContextFrame::~ContextFrame(void) std::list& ContextFrame::GetFrames(void) { - if (l_Frames.get() == NULL) + if (!l_Frames.get()) l_Frames.reset(new std::list()); return *l_Frames; diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp index 227bbfb95..5c01a0d6e 100644 --- a/lib/base/exception.cpp +++ b/lib/base/exception.cpp @@ -56,7 +56,7 @@ inline void *cast_exception(void *obj, const std::type_info *src, const std::typ if (dst->__do_catch(src, &thrown_ptr, 1)) return thrown_ptr; else - return NULL; + return nullptr; #else /* __GLIBCXX__ */ const libcxx_type_info *srcInfo = static_cast(src); const libcxx_type_info *dstInfo = static_cast(dst); @@ -66,7 +66,7 @@ inline void *cast_exception(void *obj, const std::type_info *src, const std::typ if (dstInfo->can_catch(srcInfo, adj)) return adj; else - return NULL; + return nullptr; #endif /* __GLIBCXX__ */ } @@ -128,7 +128,7 @@ void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *)) SetLastExceptionStack(stack); #ifndef NO_CAST_EXCEPTION - if (ex && boost::get_error_info(*ex) == NULL) + if (ex && !boost::get_error_info(*ex)) *ex << StackTraceErrorInfo(stack); } #endif /* NO_CAST_EXCEPTION */ @@ -137,7 +137,7 @@ void __cxa_throw(void *obj, TYPEINFO_TYPE *pvtinfo, void (*dest)(void *)) SetLastExceptionContext(context); #ifndef NO_CAST_EXCEPTION - if (ex && boost::get_error_info(*ex) == NULL) + if (ex && !boost::get_error_info(*ex)) *ex << ContextTraceErrorInfo(context); #endif /* NO_CAST_EXCEPTION */ @@ -277,7 +277,7 @@ String icinga::DiagnosticInformation(boost::exception_ptr eptr, bool verbose) try { boost::rethrow_exception(eptr); } catch (const std::exception& ex) { - return DiagnosticInformation(ex, verbose, pt ? &stack : NULL, pc ? &context : NULL); + return DiagnosticInformation(ex, verbose, pt ? &stack : nullptr, pc ? &context : nullptr); } return boost::diagnostic_information(eptr); @@ -320,7 +320,7 @@ void ScriptError::SetHandledByDebugger(bool handled) } posix_error::posix_error(void) - : m_Message(NULL) + : m_Message(nullptr) { } posix_error::~posix_error(void) throw() diff --git a/lib/base/exception.hpp b/lib/base/exception.hpp index fd4184719..7bbb21ebe 100644 --- a/lib/base/exception.hpp +++ b/lib/base/exception.hpp @@ -120,7 +120,7 @@ inline std::string to_string(const ContextTraceErrorInfo& e) return msgbuf.str(); } -I2_BASE_API String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = NULL, ContextTrace *context = NULL); +I2_BASE_API String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr); I2_BASE_API String DiagnosticInformation(boost::exception_ptr eptr, bool verbose = true); class I2_BASE_API posix_error : virtual public std::exception, virtual public boost::exception { diff --git a/lib/base/fifo.cpp b/lib/base/fifo.cpp index 374a877c8..d179dae3a 100644 --- a/lib/base/fifo.cpp +++ b/lib/base/fifo.cpp @@ -25,7 +25,7 @@ using namespace icinga; * Constructor for the FIFO class. */ FIFO::FIFO(void) - : m_Buffer(NULL), m_DataSize(0), m_AllocSize(0), m_Offset(0) + : m_Buffer(nullptr), m_DataSize(0), m_AllocSize(0), m_Offset(0) { } /** @@ -53,7 +53,7 @@ void FIFO::ResizeBuffer(size_t newSize, bool decrease) char *newBuffer = static_cast(realloc(m_Buffer, newSize)); - if (newBuffer == NULL) + if (!newBuffer) BOOST_THROW_EXCEPTION(std::bad_alloc()); m_Buffer = newBuffer; @@ -85,7 +85,7 @@ size_t FIFO::Peek(void *buffer, size_t count, bool allow_partial) if (count > m_DataSize) count = m_DataSize; - if (buffer != NULL) + if (buffer) std::memcpy(buffer, m_Buffer + m_Offset, count); return count; @@ -101,7 +101,7 @@ size_t FIFO::Read(void *buffer, size_t count, bool allow_partial) if (count > m_DataSize) count = m_DataSize; - if (buffer != NULL) + if (buffer) std::memcpy(buffer, m_Buffer + m_Offset, count); m_DataSize -= count; diff --git a/lib/base/json.cpp b/lib/base/json.cpp index df7508701..5b7bf328e 100644 --- a/lib/base/json.cpp +++ b/lib/base/json.cpp @@ -102,9 +102,9 @@ String icinga::JsonEncode(const Value& value, bool pretty_print) { #if YAJL_MAJOR < 2 yajl_gen_config conf = { pretty_print, "" }; - yajl_gen handle = yajl_gen_alloc(&conf, NULL); + yajl_gen handle = yajl_gen_alloc(&conf, nullptr); #else /* YAJL_MAJOR */ - yajl_gen handle = yajl_gen_alloc(NULL); + yajl_gen handle = yajl_gen_alloc(nullptr); if (pretty_print) yajl_gen_config(handle, yajl_gen_beautify, 1); #endif /* YAJL_MAJOR */ @@ -307,8 +307,8 @@ Value icinga::JsonDecode(const String& data) static const yajl_callbacks callbacks = { DecodeNull, DecodeBoolean, - NULL, - NULL, + nullptr, + nullptr, DecodeNumber, DecodeString, DecodeStartMap, @@ -325,9 +325,9 @@ Value icinga::JsonDecode(const String& data) JsonContext context; #if YAJL_MAJOR < 2 - handle = yajl_alloc(&callbacks, &cfg, NULL, &context); + handle = yajl_alloc(&callbacks, &cfg, nullptr, &context); #else /* YAJL_MAJOR */ - handle = yajl_alloc(&callbacks, NULL, &context); + handle = yajl_alloc(&callbacks, nullptr, &context); yajl_config(handle, yajl_dont_validate_strings, 1); yajl_config(handle, yajl_allow_comments, 1); #endif /* YAJL_MAJOR */ diff --git a/lib/base/loader.cpp b/lib/base/loader.cpp index 9988b609a..7a8c27eb1 100644 --- a/lib/base/loader.cpp +++ b/lib/base/loader.cpp @@ -46,7 +46,7 @@ void Loader::LoadExtensionLibrary(const String& library) #ifdef _WIN32 HMODULE hModule = LoadLibrary(path.CStr()); - if (hModule == NULL) { + if (!hModule) { BOOST_THROW_EXCEPTION(win32_error() << boost::errinfo_api_function("LoadLibrary") << errinfo_win32_error(GetLastError()) @@ -55,7 +55,7 @@ void Loader::LoadExtensionLibrary(const String& library) #else /* _WIN32 */ void *hModule = dlopen(path.CStr(), RTLD_NOW | RTLD_GLOBAL); - if (hModule == NULL) { + if (!hModule) { BOOST_THROW_EXCEPTION(std::runtime_error("Could not load library '" + path + "': " + dlerror())); } #endif /* _WIN32 */ diff --git a/lib/base/networkstream.cpp b/lib/base/networkstream.cpp index 3fc443ca0..8213859cd 100644 --- a/lib/base/networkstream.cpp +++ b/lib/base/networkstream.cpp @@ -35,7 +35,7 @@ void NetworkStream::Close(void) /** * Reads data from the stream. * - * @param buffer The buffer where data should be stored. May be NULL if you're + * @param buffer The buffer where data should be stored. May be nullptr if you're * not actually interested in the data. * @param count The number of bytes to read from the queue. * @returns The number of bytes actually read. diff --git a/lib/base/objectlock.hpp b/lib/base/objectlock.hpp index 51a376f14..3908d27a4 100644 --- a/lib/base/objectlock.hpp +++ b/lib/base/objectlock.hpp @@ -35,7 +35,7 @@ struct I2_BASE_API ObjectLock { public: inline ObjectLock(void) - : m_Object(NULL), m_Locked(false) + : m_Object(nullptr), m_Locked(false) { } inline ~ObjectLock(void) @@ -96,7 +96,7 @@ public: inline void Lock(void) { - ASSERT(!m_Locked && m_Object != NULL); + ASSERT(!m_Locked && m_Object); LockMutex(m_Object); diff --git a/lib/base/objecttype.cpp b/lib/base/objecttype.cpp index e5cdba372..d0613db8e 100644 --- a/lib/base/objecttype.cpp +++ b/lib/base/objecttype.cpp @@ -58,7 +58,7 @@ int ObjectType::GetFieldId(const String& name) const Field ObjectType::GetFieldInfo(int id) const { if (id == 0) - return Field(1, "String", "type", NULL, NULL, 0, 0); + return Field(1, "String", "type", nullptr, nullptr, 0, 0); else BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID.")); } diff --git a/lib/base/primitivetype.hpp b/lib/base/primitivetype.hpp index 808a4160a..f1d416a51 100644 --- a/lib/base/primitivetype.hpp +++ b/lib/base/primitivetype.hpp @@ -71,7 +71,7 @@ private: REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactoryVA) #define REGISTER_PRIMITIVE_TYPE_NOINST(type, base, prototype) \ - REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, NULL) + REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, nullptr) } diff --git a/lib/base/process.cpp b/lib/base/process.cpp index 2f8590f78..408175172 100644 --- a/lib/base/process.cpp +++ b/lib/base/process.cpp @@ -72,7 +72,7 @@ Process::Process(const Process::Arguments& arguments, const Dictionary::Ptr& ext #endif /* _WIN32 */ { #ifdef _WIN32 - m_Overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + m_Overlapped.hEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); #endif /* _WIN32 */ } @@ -88,7 +88,7 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques { struct cmsghdr *cmsg = CMSG_FIRSTHDR(msgh); - if (cmsg == NULL || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_len != CMSG_LEN(sizeof(int) * 3)) { + if (cmsg == nullptr || cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_len != CMSG_LEN(sizeof(int) * 3)) { std::cerr << "Invalid 'spawn' request: FDs missing" << std::endl; return Empty; } @@ -107,13 +107,13 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques argv[i] = strdup(arg.CStr()); } - argv[arguments->GetLength()] = NULL; + argv[arguments->GetLength()] = nullptr; // build envp int envc = 0; /* count existing environment variables */ - while (environ[envc] != NULL) + while (environ[envc]) envc++; char **envp = new char *[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 2]; @@ -133,7 +133,7 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques } envp[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0)] = strdup("LC_NUMERIC=C"); - envp[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 1] = NULL; + envp[envc + (extraEnvironment ? extraEnvironment->GetLength() : 0) + 1] = nullptr; extraEnvironment.reset(); @@ -170,7 +170,7 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques sigset_t mask; sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); + sigprocmask(SIG_SETMASK, &mask, nullptr); if (icinga2_execvpe(argv[0], argv, envp) < 0) { char errmsg[512]; @@ -190,13 +190,13 @@ static Value ProcessSpawnImpl(struct msghdr *msgh, const Dictionary::Ptr& reques (void)close(fds[2]); // free arguments - for (int i = 0; argv[i] != NULL; i++) + for (int i = 0; argv[i]; i++) free(argv[i]); delete[] argv; // free environment - for (int i = 0; envp[i] != NULL; i++) + for (int i = 0; envp[i]; i++) free(envp[i]); delete[] envp; @@ -241,7 +241,7 @@ static void ProcessHandler(void) { sigset_t mask; sigfillset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); + sigprocmask(SIG_SETMASK, &mask, nullptr); rlimit rl; if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) { @@ -508,7 +508,7 @@ static void InitializeProcess(void) { for (int tid = 0; tid < IOTHREADS; tid++) { #ifdef _WIN32 - l_Events[tid] = CreateEvent(NULL, TRUE, FALSE, NULL); + l_Events[tid] = CreateEvent(nullptr, TRUE, FALSE, nullptr); #else /* _WIN32 */ # ifdef HAVE_PIPE2 if (pipe2(l_EventFDs[tid], O_CLOEXEC) < 0) { @@ -601,10 +601,10 @@ bool Process::GetAdjustPriority(void) const void Process::IOThreadProc(int tid) { #ifdef _WIN32 - HANDLE *handles = NULL; - HANDLE *fhandles = NULL; + HANDLE *handles = nullptr; + HANDLE *fhandles = nullptr; #else /* _WIN32 */ - pollfd *pfds = NULL; + pollfd *pfds = nullptr; #endif /* _WIN32 */ int count = 0; double now; @@ -773,7 +773,7 @@ static BOOL CreatePipeOverlapped(HANDLE *outReadPipe, HANDLE *outWritePipe, if (*outReadPipe == INVALID_HANDLE_VALUE) return FALSE; - *outWritePipe = CreateFile(pipeName, GENERIC_WRITE, 0, securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | writeMode, NULL); + *outWritePipe = CreateFile(pipeName, GENERIC_WRITE, 0, securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | writeMode, nullptr); if (*outWritePipe == INVALID_HANDLE_VALUE) { DWORD error = GetLastError(); @@ -821,7 +821,7 @@ void Process::Run(const std::function& callback) /* LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; SIZE_T cbSize; - if (!InitializeProcThreadAttributeList(NULL, 1, 0, &cbSize) && GetLastError() != ERROR_INSUFFICIENT_BUFFER) + if (!InitializeProcThreadAttributeList(nullptr, 1, 0, &cbSize) && GetLastError() != ERROR_INSUFFICIENT_BUFFER) BOOST_THROW_EXCEPTION(win32_error() << boost::errinfo_api_function("InitializeProcThreadAttributeList") << errinfo_win32_error(GetLastError())); @@ -839,7 +839,7 @@ void Process::Run(const std::function& callback) rgHandles[2] = GetStdHandle(STD_INPUT_HANDLE); if (!UpdateProcThreadAttribute(lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_HANDLE_LIST, - rgHandles, sizeof(rgHandles), NULL, NULL)) + rgHandles, sizeof(rgHandles), nullptr, nullptr)) BOOST_THROW_EXCEPTION(win32_error() << boost::errinfo_api_function("UpdateProcThreadAttribute") << errinfo_win32_error(GetLastError())); @@ -862,7 +862,7 @@ void Process::Run(const std::function& callback) LPCH pEnvironment = GetEnvironmentStrings(); size_t ioffset = 0, offset = 0; - char *envp = NULL; + char *envp = nullptr; for (;;) { size_t len = strlen(pEnvironment + ioffset); @@ -878,7 +878,7 @@ void Process::Run(const std::function& callback) envp = static_cast(realloc(envp, offset + len + 1)); - if (envp == NULL) + if (!envp) BOOST_THROW_EXCEPTION(std::bad_alloc()); strcpy(envp + offset, pEnvironment + ioffset); @@ -896,7 +896,7 @@ void Process::Run(const std::function& callback) envp = static_cast(realloc(envp, offset + skv.GetLength() + 1)); - if (envp == NULL) + if (!envp) BOOST_THROW_EXCEPTION(std::bad_alloc()); strcpy(envp + offset, skv.CStr()); @@ -906,13 +906,13 @@ void Process::Run(const std::function& callback) envp = static_cast(realloc(envp, offset + 1)); - if (envp == NULL) + if (!envp) BOOST_THROW_EXCEPTION(std::bad_alloc()); envp[offset] = '\0'; - if (!CreateProcess(NULL, args, NULL, NULL, TRUE, - 0 /*EXTENDED_STARTUPINFO_PRESENT*/, envp, NULL, &si.StartupInfo, &pi)) { + if (!CreateProcess(nullptr, args, nullptr, nullptr, TRUE, + 0 /*EXTENDED_STARTUPINFO_PRESENT*/, envp, nullptr, &si.StartupInfo, &pi)) { DWORD error = GetLastError(); CloseHandle(outWritePipe); CloseHandle(outWritePipeDup); diff --git a/lib/base/scriptglobal.hpp b/lib/base/scriptglobal.hpp index 7e3d14270..2a7d3629f 100644 --- a/lib/base/scriptglobal.hpp +++ b/lib/base/scriptglobal.hpp @@ -34,7 +34,7 @@ namespace icinga class I2_BASE_API ScriptGlobal { public: - static Value Get(const String& name, const Value *defaultValue = NULL); + static Value Get(const String& name, const Value *defaultValue = nullptr); static void Set(const String& name, const Value& value); static bool Exists(const String& name); diff --git a/lib/base/serializer.cpp b/lib/base/serializer.cpp index c05fdabfd..05ddce49a 100644 --- a/lib/base/serializer.cpp +++ b/lib/base/serializer.cpp @@ -155,12 +155,12 @@ Value icinga::Serialize(const Value& value, int attributeTypes) Array::Ptr array = dynamic_pointer_cast(input); - if (array != NULL) + if (array) return SerializeArray(array, attributeTypes); Dictionary::Ptr dict = dynamic_pointer_cast(input); - if (dict != NULL) + if (dict) return SerializeDictionary(dict, attributeTypes); return SerializeObject(input, attributeTypes); @@ -180,12 +180,12 @@ Value icinga::Deserialize(const Object::Ptr& object, const Value& value, bool sa Array::Ptr array = dynamic_pointer_cast(input); - if (array != NULL) + if (array) return DeserializeArray(array, safe_mode, attributeTypes); Dictionary::Ptr dict = dynamic_pointer_cast(input); - ASSERT(dict != NULL); + ASSERT(dict); if ((safe_mode && !object) || !dict->Contains("type")) return DeserializeDictionary(dict, safe_mode, attributeTypes); diff --git a/lib/base/socket.hpp b/lib/base/socket.hpp index 12834233b..a748ec2ed 100644 --- a/lib/base/socket.hpp +++ b/lib/base/socket.hpp @@ -53,7 +53,7 @@ public: void Listen(void); Socket::Ptr Accept(void); - bool Poll(bool read, bool write, struct timeval *timeout = NULL); + bool Poll(bool read, bool write, struct timeval *timeout = nullptr); void MakeNonBlocking(void); diff --git a/lib/base/socketevents-epoll.cpp b/lib/base/socketevents-epoll.cpp index 589fe789a..6b775abe2 100644 --- a/lib/base/socketevents-epoll.cpp +++ b/lib/base/socketevents-epoll.cpp @@ -174,7 +174,7 @@ void SocketEventEngineEpoll::Unregister(SocketEvents *se) m_Sockets[tid].erase(se->m_FD); m_FDChanged[tid] = true; - epoll_ctl(m_PollFDs[tid], EPOLL_CTL_DEL, se->m_FD, NULL); + epoll_ctl(m_PollFDs[tid], EPOLL_CTL_DEL, se->m_FD, nullptr); se->m_FD = INVALID_SOCKET; se->m_Events = false; diff --git a/lib/base/socketevents.cpp b/lib/base/socketevents.cpp index 8b77da1a0..26fbb9223 100644 --- a/lib/base/socketevents.cpp +++ b/lib/base/socketevents.cpp @@ -112,7 +112,7 @@ void SocketEvents::InitializeEngine(void) * Constructor for the SocketEvents class. */ SocketEvents::SocketEvents(const Socket::Ptr& socket, Object *lifesupportObject) - : m_ID(m_NextID++), m_FD(socket->GetFD()), m_EnginePrivate(NULL) + : m_ID(m_NextID++), m_FD(socket->GetFD()), m_EnginePrivate(nullptr) { boost::call_once(l_SocketIOOnceFlag, &SocketEvents::InitializeEngine); diff --git a/lib/base/socketevents.hpp b/lib/base/socketevents.hpp index c40d36430..23262258c 100644 --- a/lib/base/socketevents.hpp +++ b/lib/base/socketevents.hpp @@ -82,7 +82,7 @@ struct SocketEventDescriptor Object *LifesupportObject; SocketEventDescriptor(void) - : Events(POLLIN), EventInterface(NULL), LifesupportObject(NULL) + : Events(POLLIN), EventInterface(nullptr), LifesupportObject(nullptr) { } }; diff --git a/lib/base/stacktrace.cpp b/lib/base/stacktrace.cpp index e4fa7249c..65aaafd79 100644 --- a/lib/base/stacktrace.cpp +++ b/lib/base/stacktrace.cpp @@ -37,7 +37,7 @@ StackTrace::StackTrace(void) m_Count = backtrace(m_Frames, sizeof(m_Frames) / sizeof(m_Frames[0])); #else /* HAVE_BACKTRACE_SYMBOLS */ # ifdef _WIN32 - m_Count = CaptureStackBackTrace(0, sizeof(m_Frames) / sizeof(m_Frames), m_Frames, NULL); + m_Count = CaptureStackBackTrace(0, sizeof(m_Frames) / sizeof(m_Frames), m_Frames, nullptr); # else /* _WIN32 */ m_Count = 0; # endif /* _WIN32 */ @@ -75,8 +75,8 @@ StackTrace::StackTrace(PEXCEPTION_POINTERS exi) m_Count = 0; while (StackWalk64(architecture, GetCurrentProcess(), GetCurrentThread(), - &frame, exi->ContextRecord, NULL, &SymFunctionTableAccess64, - &SymGetModuleBase64, NULL) && m_Count < sizeof(m_Frames) / sizeof(m_Frames[0])) { + &frame, exi->ContextRecord, nullptr, &SymFunctionTableAccess64, + &SymGetModuleBase64, nullptr) && m_Count < sizeof(m_Frames) / sizeof(m_Frames[0])) { m_Frames[m_Count] = reinterpret_cast(frame.AddrPC.Offset); m_Count++; } @@ -86,7 +86,7 @@ StackTrace::StackTrace(PEXCEPTION_POINTERS exi) #ifdef _WIN32 INITIALIZE_ONCE([]() { (void) SymSetOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES); - (void) SymInitialize(GetCurrentProcess(), NULL, TRUE); + (void) SymInitialize(GetCurrentProcess(), nullptr, TRUE); }); #endif /* _WIN32 */ @@ -106,7 +106,7 @@ void StackTrace::Print(std::ostream& fp, int ignoreFrames) const # ifdef HAVE_BACKTRACE_SYMBOLS char **messages = backtrace_symbols(m_Frames, m_Count); - for (int i = ignoreFrames + 1; i < m_Count && messages != NULL; ++i) { + for (int i = ignoreFrames + 1; i < m_Count && messages; ++i) { String message = messages[i]; char *sym_begin = strchr(messages[i], '('); @@ -114,7 +114,7 @@ void StackTrace::Print(std::ostream& fp, int ignoreFrames) const if (sym_begin) { char *sym_end = strchr(sym_begin, '+'); - if (sym_end != NULL) { + if (sym_end) { String sym = String(sym_begin + 1, sym_end); String sym_demangled = Utility::DemangleSymbolName(sym); diff --git a/lib/base/stream.hpp b/lib/base/stream.hpp index bf79a7768..c4a6a7af1 100644 --- a/lib/base/stream.hpp +++ b/lib/base/stream.hpp @@ -39,7 +39,7 @@ enum ConnectionRole struct I2_BASE_API StreamReadContext { StreamReadContext(void) - : Buffer(NULL), Size(0), MustRead(true), Eof(false) + : Buffer(nullptr), Size(0), MustRead(true), Eof(false) { } ~StreamReadContext(void) @@ -76,7 +76,7 @@ public: /** * Reads data from the stream without removing it from the stream buffer. * - * @param buffer The buffer where data should be stored. May be NULL if you're + * @param buffer The buffer where data should be stored. May be nullptr if you're * not actually interested in the data. * @param count The number of bytes to read from the queue. * @param allow_partial Whether to allow partial reads. @@ -87,7 +87,7 @@ public: /** * Reads data from the stream. * - * @param buffer The buffer where data should be stored. May be NULL if you're + * @param buffer The buffer where data should be stored. May be nullptr if you're * not actually interested in the data. * @param count The number of bytes to read from the queue. * @param allow_partial Whether to allow partial reads. diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index cb36a3d40..1bc999970 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -34,7 +34,7 @@ boost::mutex StreamLogger::m_Mutex; * Constructor for the StreamLogger class. */ StreamLogger::StreamLogger(void) - : m_Stream(NULL), m_OwnsStream(false) + : m_Stream(nullptr), m_OwnsStream(false) { } void StreamLogger::Stop(bool runtimeRemoved) diff --git a/lib/base/tcpsocket.cpp b/lib/base/tcpsocket.cpp index 113306436..a3dcc1429 100644 --- a/lib/base/tcpsocket.cpp +++ b/lib/base/tcpsocket.cpp @@ -58,7 +58,7 @@ void TcpSocket::Bind(const String& node, const String& service, int family) hints.ai_protocol = IPPROTO_TCP; hints.ai_flags = AI_PASSIVE; - int rc = getaddrinfo(node.IsEmpty() ? NULL : node.CStr(), + int rc = getaddrinfo(node.IsEmpty() ? nullptr : node.CStr(), service.CStr(), &hints, &result); if (rc != 0) { @@ -72,7 +72,7 @@ void TcpSocket::Bind(const String& node, const String& service, int family) int fd = INVALID_SOCKET; - for (addrinfo *info = result; info != NULL; info = info->ai_next) { + for (addrinfo *info = result; info != nullptr; info = info->ai_next) { fd = socket(info->ai_family, info->ai_socktype, info->ai_protocol); if (fd == INVALID_SOCKET) { @@ -163,7 +163,7 @@ void TcpSocket::Connect(const String& node, const String& service) SOCKET fd = INVALID_SOCKET; - for (addrinfo *info = result; info != NULL; info = info->ai_next) { + for (addrinfo *info = result; info != nullptr; info = info->ai_next) { fd = socket(info->ai_family, info->ai_socktype, info->ai_protocol); if (fd == INVALID_SOCKET) { diff --git a/lib/base/threadpool.hpp b/lib/base/threadpool.hpp index d49ffa414..ecef5d9fe 100644 --- a/lib/base/threadpool.hpp +++ b/lib/base/threadpool.hpp @@ -83,7 +83,7 @@ private: boost::thread *Thread; WorkerThread(ThreadState state = ThreadDead) - : State(state), Zombie(false), Utilization(0), LastUpdate(0), Thread(NULL) + : State(state), Zombie(false), Utilization(0), LastUpdate(0), Thread(nullptr) { } void UpdateUtilization(ThreadState state = ThreadUnspecified); diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index 6f8f0664c..c9f14667f 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -58,7 +58,7 @@ TlsStream::TlsStream(const Socket::Ptr& socket, const String& hostname, Connecti } if (!m_SSLIndexInitialized) { - m_SSLIndex = SSL_get_ex_new_index(0, const_cast("TlsStream"), NULL, NULL, NULL); + m_SSLIndex = SSL_get_ex_new_index(0, const_cast("TlsStream"), nullptr, nullptr, nullptr); m_SSLIndexInitialized = true; } @@ -187,7 +187,7 @@ void TlsStream::OnEvent(int revents) rc = SSL_write(m_SSL.get(), buffer, count); if (rc > 0) { - m_SendQ->Read(NULL, rc, true); + m_SendQ->Read(nullptr, rc, true); success = true; } @@ -232,7 +232,7 @@ void TlsStream::OnEvent(int revents) if (m_ErrorCode != 0) { Log(LogWarning, "TlsStream") - << "OpenSSL error: " << ERR_error_string(m_ErrorCode, NULL); + << "OpenSSL error: " << ERR_error_string(m_ErrorCode, nullptr); } else { Log(LogWarning, "TlsStream", "TLS stream was disconnected."); } diff --git a/lib/base/tlsutility.cpp b/lib/base/tlsutility.cpp index 04a6bd1ed..e357ad40c 100644 --- a/lib/base/tlsutility.cpp +++ b/lib/base/tlsutility.cpp @@ -142,7 +142,7 @@ std::shared_ptr MakeSSLContext(const String& pubkey, const String& priv } if (!cakey.IsEmpty()) { - if (!SSL_CTX_load_verify_locations(sslContext.get(), cakey.CStr(), NULL)) { + if (!SSL_CTX_load_verify_locations(sslContext.get(), cakey.CStr(), nullptr)) { Log(LogCritical, "SSL") << "Error loading and verifying locations in ca key file '" << cakey << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; BOOST_THROW_EXCEPTION(openssl_error() @@ -154,7 +154,7 @@ std::shared_ptr MakeSSLContext(const String& pubkey, const String& priv STACK_OF(X509_NAME) *cert_names; cert_names = SSL_load_client_CA_file(cakey.CStr()); - if (cert_names == NULL) { + if (!cert_names) { Log(LogCritical, "SSL") << "Error loading client ca key file '" << cakey << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; BOOST_THROW_EXCEPTION(openssl_error() @@ -298,7 +298,7 @@ std::shared_ptr GetX509Certificate(const String& pemfile) X509 *cert; BIO *fpcert = BIO_new(BIO_s_file()); - if (fpcert == NULL) { + if (!fpcert) { Log(LogCritical, "SSL") << "Error creating new BIO: " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; BOOST_THROW_EXCEPTION(openssl_error() @@ -315,8 +315,8 @@ std::shared_ptr GetX509Certificate(const String& pemfile) << boost::errinfo_file_name(pemfile)); } - cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL); - if (cert == NULL) { + cert = PEM_read_bio_X509_AUX(fpcert, nullptr, nullptr, nullptr); + if (!cert) { Log(LogCritical, "SSL") << "Error on bio X509 AUX reading pem file '" << pemfile << "': " << ERR_peek_error() << ", \"" << ERR_error_string(ERR_peek_error(), errbuf) << "\""; BOOST_THROW_EXCEPTION(openssl_error() @@ -379,7 +379,7 @@ int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile, << boost::errinfo_file_name(keyfile)); } - if (!PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, 0, NULL)) { + if (!PEM_write_bio_PrivateKey(bio, key, nullptr, nullptr, 0, 0, nullptr)) { EVP_PKEY_free(key); EC_KEY_free(eckey); BIO_free(bio); @@ -446,7 +446,7 @@ int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile, if (!ca) { String san = "DNS:" + cn; - X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(NULL, NULL, NID_subject_alt_name, const_cast(san.CStr())); + X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(nullptr, nullptr, NID_subject_alt_name, const_cast(san.CStr())); if (subjectAltNameExt) { /* OpenSSL 0.9.8 requires STACK_OF(X509_EXTENSION), otherwise we would just use stack_st_X509_EXTENSION. */ STACK_OF(X509_EXTENSION) *exts = sk_X509_EXTENSION_new_null(); @@ -539,7 +539,7 @@ std::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME X509V3_CTX ctx; X509V3_set_ctx_nodb(&ctx); - X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0); + X509V3_set_ctx(&ctx, cert, cert, nullptr, nullptr, 0); const char *attr; @@ -548,7 +548,7 @@ std::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME else attr = "critical,CA:FALSE"; - X509_EXTENSION *basicConstraintsExt = X509V3_EXT_conf_nid(NULL, &ctx, NID_basic_constraints, const_cast(attr)); + X509_EXTENSION *basicConstraintsExt = X509V3_EXT_conf_nid(nullptr, &ctx, NID_basic_constraints, const_cast(attr)); if (basicConstraintsExt) { X509_add_ext(cert, basicConstraintsExt, -1); @@ -559,7 +559,7 @@ std::shared_ptr CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME if (!ca) { String san = "DNS:" + cn; - X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(NULL, &ctx, NID_subject_alt_name, const_cast(san.CStr())); + X509_EXTENSION *subjectAltNameExt = X509V3_EXT_conf_nid(nullptr, &ctx, NID_subject_alt_name, const_cast(san.CStr())); if (subjectAltNameExt) { X509_add_ext(cert, subjectAltNameExt, -1); X509_EXTENSION_free(subjectAltNameExt); @@ -592,7 +592,7 @@ std::shared_ptr CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject) return std::shared_ptr(); } - EVP_PKEY *privkey = PEM_read_bio_PrivateKey(cakeybio, NULL, NULL, NULL); + EVP_PKEY *privkey = PEM_read_bio_PrivateKey(cakeybio, nullptr, nullptr, nullptr); if (!privkey) { Log(LogCritical, "SSL") @@ -635,7 +635,7 @@ std::shared_ptr StringToCertificate(const String& cert) BIO *bio = BIO_new(BIO_s_mem()); BIO_write(bio, (const void *)cert.CStr(), cert.GetLength()); - X509 *rawCert = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL); + X509 *rawCert = PEM_read_bio_X509_AUX(bio, nullptr, nullptr, nullptr); BIO_free(bio); @@ -772,7 +772,7 @@ bool VerifyCertificate(const std::shared_ptr& caCertificate, const std::sh X509_STORE_add_cert(store, caCertificate.get()); X509_STORE_CTX *csc = X509_STORE_CTX_new(); - X509_STORE_CTX_init(csc, store, certificate.get(), NULL); + X509_STORE_CTX_init(csc, store, certificate.get(), nullptr); int rc = X509_verify_cert(csc); diff --git a/lib/base/tlsutility.hpp b/lib/base/tlsutility.hpp index 161907104..e7734767c 100644 --- a/lib/base/tlsutility.hpp +++ b/lib/base/tlsutility.hpp @@ -69,7 +69,7 @@ inline std::string to_string(const errinfo_openssl_error& e) const char *message = ERR_error_string(code, errbuf); - if (message == NULL) + if (!message) message = "Unknown error."; tmp << code << ", \"" << message << "\""; diff --git a/lib/base/type.cpp b/lib/base/type.cpp index f58d6e193..6ea216a2c 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -39,7 +39,7 @@ String Type::ToString(void) const void Type::Register(const Type::Ptr& type) { - VERIFY(GetByName(type->GetName()) == NULL); + VERIFY(!GetByName(type->GetName())); ScriptGlobal::Set("Types." + type->GetName(), type); } @@ -195,11 +195,11 @@ Field TypeType::GetFieldInfo(int id) const return GetBaseType()->GetFieldInfo(id); if (real_id == 0) - return Field(0, "String", "name", "", NULL, 0, 0); + return Field(0, "String", "name", "", nullptr, 0, 0); else if (real_id == 1) - return Field(1, "Object", "prototype", "", NULL, 0, 0); + return Field(1, "Object", "prototype", "", nullptr, 0, 0); else if (real_id == 2) - return Field(2, "Type", "base", "", NULL, 0, 0); + return Field(2, "Type", "base", "", nullptr, 0, 0); throw std::runtime_error("Invalid field ID."); } @@ -211,6 +211,6 @@ int TypeType::GetFieldCount(void) const ObjectFactory TypeType::GetFactory(void) const { - return NULL; + return nullptr; } diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp index 24d5b1b92..19ab1a598 100644 --- a/lib/base/utility.cpp +++ b/lib/base/utility.cpp @@ -85,7 +85,7 @@ String Utility::DemangleSymbolName(const String& sym) int status; char *realname = abi::__cxa_demangle(sym.CStr(), 0, 0, &status); - if (realname != NULL) { + if (realname) { result = String(realname); free(realname); } @@ -277,7 +277,7 @@ String Utility::DirName(const String& path) dir = strdup(path.CStr()); #endif /* _WIN32 */ - if (dir == NULL) + if (!dir) BOOST_THROW_EXCEPTION(std::bad_alloc()); String result; @@ -315,7 +315,7 @@ String Utility::BaseName(const String& path) char *dir = strdup(path.CStr()); String result; - if (dir == NULL) + if (!dir) BOOST_THROW_EXCEPTION(std::bad_alloc()); #ifndef _WIN32 @@ -395,7 +395,7 @@ double Utility::GetTime(void) #else /* _WIN32 */ struct timeval tv; - int rc = gettimeofday(&tv, NULL); + int rc = gettimeofday(&tv, nullptr); VERIFY(rc >= 0); return tv.tv_sec + tv.tv_usec / 1000000.0; @@ -664,7 +664,7 @@ bool Utility::GlobRecursive(const String& path, const String& pattern, const std dirp = opendir(path.CStr()); - if (dirp == NULL) + if (!dirp) BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("opendir") << boost::errinfo_errno(errno) @@ -1017,7 +1017,7 @@ String Utility::FormatDateTime(const char *format, double ts) #ifdef _MSC_VER tm *temp = localtime(&tempts); - if (temp == NULL) { + if (!temp) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("localtime") << boost::errinfo_errno(errno)); @@ -1025,7 +1025,7 @@ String Utility::FormatDateTime(const char *format, double ts) tmthen = *temp; #else /* _MSC_VER */ - if (localtime_r(&tempts, &tmthen) == NULL) { + if (!localtime_r(&tempts, &tmthen)) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("localtime_r") << boost::errinfo_errno(errno)); @@ -1045,8 +1045,8 @@ String Utility::FormatErrorNumber(int code) { String result = "Unknown error."; DWORD rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, 0, (char *)&message, - 0, NULL); + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, code, 0, (char *)&message, + 0, nullptr); if (rc != 0) { result = String(message); @@ -1295,10 +1295,10 @@ String Utility::GetFQDN(void) hints.ai_flags = AI_CANONNAME; addrinfo *result; - int rc = getaddrinfo(hostname.CStr(), NULL, &hints, &result); + int rc = getaddrinfo(hostname.CStr(), nullptr, &hints, &result); if (rc != 0) - result = NULL; + result = nullptr; if (result) { if (strcmp(result->ai_canonname, "localhost") != 0) @@ -1331,7 +1331,7 @@ tm Utility::LocalTime(time_t ts) #ifdef _MSC_VER tm *result = localtime(&ts); - if (result == NULL) { + if (!result) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("localtime") << boost::errinfo_errno(errno)); @@ -1341,7 +1341,7 @@ tm Utility::LocalTime(time_t ts) #else /* _MSC_VER */ tm result; - if (localtime_r(&ts, &result) == NULL) { + if (!localtime_r(&ts, &result)) { BOOST_THROW_EXCEPTION(posix_error() << boost::errinfo_api_function("localtime_r") << boost::errinfo_errno(errno)); @@ -1479,7 +1479,7 @@ static String UnameHelper(char type) char line[1024]; std::ostringstream msgbuf; - while (fgets(line, sizeof(line), fp) != NULL) + while (fgets(line, sizeof(line), fp)) msgbuf << line; pclose(fp); @@ -1557,10 +1557,10 @@ static bool ReleaseHelper(String *platformName, String *platformVersion) /* You are using a distribution which supports LSB. */ FILE *fp = popen("type lsb_release >/dev/null 2>&1 && lsb_release -s -i 2>&1", "r"); - if (fp != NULL) { + if (fp) { std::ostringstream msgbuf; char line[1024]; - while (fgets(line, sizeof(line), fp) != NULL) + while (fgets(line, sizeof(line), fp)) msgbuf << line; int status = pclose(fp); if (WEXITSTATUS(status) == 0) { @@ -1571,10 +1571,10 @@ static bool ReleaseHelper(String *platformName, String *platformVersion) fp = popen("type lsb_release >/dev/null 2>&1 && lsb_release -s -r 2>&1", "r"); - if (fp != NULL) { + if (fp) { std::ostringstream msgbuf; char line[1024]; - while (fgets(line, sizeof(line), fp) != NULL) + while (fgets(line, sizeof(line), fp)) msgbuf << line; int status = pclose(fp); if (WEXITSTATUS(status) == 0) { @@ -1586,10 +1586,10 @@ static bool ReleaseHelper(String *platformName, String *platformVersion) /* OS X */ fp = popen("type sw_vers >/dev/null 2>&1 && sw_vers -productName 2>&1", "r"); - if (fp != NULL) { + if (fp) { std::ostringstream msgbuf; char line[1024]; - while (fgets(line, sizeof(line), fp) != NULL) + while (fgets(line, sizeof(line), fp)) msgbuf << line; int status = pclose(fp); if (WEXITSTATUS(status) == 0) { @@ -1603,10 +1603,10 @@ static bool ReleaseHelper(String *platformName, String *platformVersion) fp = popen("type sw_vers >/dev/null 2>&1 && sw_vers -productVersion 2>&1", "r"); - if (fp != NULL) { + if (fp) { std::ostringstream msgbuf; char line[1024]; - while (fgets(line, sizeof(line), fp) != NULL) + while (fgets(line, sizeof(line), fp)) msgbuf << line; int status = pclose(fp); if (WEXITSTATUS(status) == 0) { @@ -1690,7 +1690,7 @@ String Utility::GetPlatformKernelVersion(void) String Utility::GetPlatformName(void) { String platformName; - if (!ReleaseHelper(&platformName, NULL)) + if (!ReleaseHelper(&platformName, nullptr)) return "Unknown"; return platformName; } @@ -1698,7 +1698,7 @@ String Utility::GetPlatformName(void) String Utility::GetPlatformVersion(void) { String platformVersion; - if (!ReleaseHelper(NULL, &platformVersion)) + if (!ReleaseHelper(nullptr, &platformVersion)) return "Unknown"; return platformVersion; } @@ -1928,7 +1928,7 @@ String Utility::GetIcingaInstallPath(void) String Utility::GetIcingaDataPath(void) { char path[MAX_PATH]; - if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path))) + if (!SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_COMMON_APPDATA, nullptr, 0, path))) return ""; return String(path) + "\\icinga2"; } diff --git a/lib/base/value.hpp b/lib/base/value.hpp index 0eab3712c..996a6a25b 100644 --- a/lib/base/value.hpp +++ b/lib/base/value.hpp @@ -259,7 +259,7 @@ public: if (!IsObject()) return false; - return (dynamic_cast(boost::get(m_Value).get()) != NULL); + return dynamic_cast(boost::get(m_Value).get()); } /** diff --git a/lib/cli/clicommand.hpp b/lib/cli/clicommand.hpp index 3b150505d..b678c8218 100644 --- a/lib/cli/clicommand.hpp +++ b/lib/cli/clicommand.hpp @@ -78,9 +78,9 @@ public: CLICommand::Ptr& command, bool autocomplete); static void ShowCommands(int argc, char **argv, - boost::program_options::options_description *visibleDesc = NULL, - boost::program_options::options_description *hiddenDesc = NULL, - ArgumentCompletionCallback globalArgCompletionCallback = NULL, + boost::program_options::options_description *visibleDesc = nullptr, + boost::program_options::options_description *hiddenDesc = nullptr, + ArgumentCompletionCallback globalArgCompletionCallback = nullptr, bool autocomplete = false, int autoindex = -1); private: diff --git a/lib/cli/consolecommand.cpp b/lib/cli/consolecommand.cpp index 42a225b4a..0ace2fc69 100644 --- a/lib/cli/consolecommand.cpp +++ b/lib/cli/consolecommand.cpp @@ -68,7 +68,7 @@ extern "C" void dbg_inspect_object(Object *obj) extern "C" void dbg_eval(const char *text) { - Expression *expr = NULL; + Expression *expr = nullptr; try { ScriptFrame frame; @@ -84,7 +84,7 @@ extern "C" void dbg_eval(const char *text) extern "C" void dbg_eval_with_value(const Value& value, const char *text) { - Expression *expr = NULL; + Expression *expr = nullptr; try { ScriptFrame frame; @@ -102,7 +102,7 @@ extern "C" void dbg_eval_with_value(const Value& value, const char *text) extern "C" void dbg_eval_with_object(Object *object, const char *text) { - Expression *expr = NULL; + Expression *expr = nullptr; try { ScriptFrame frame; @@ -214,7 +214,7 @@ char *ConsoleCommand::ConsoleCompleteHelper(const char *word, int state) } if (state >= static_cast(matches.size())) - return NULL; + return nullptr; return strdup(matches[state].CStr()); } @@ -400,7 +400,7 @@ incomplete: command += line; - Expression *expr = NULL; + Expression *expr = nullptr; try { lines[fileName] = command; diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index e9d0d60d6..199552b92 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -306,7 +306,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector() && frame.Self.Get()->HasOwnField(m_Variable)) { *parent = frame.Self; @@ -149,7 +149,7 @@ bool VariableExpression::GetReference(ScriptFrame& frame, bool init_dict, Value *parent = ScriptGlobal::GetGlobals(); if (dhint) - *dhint = NULL; + *dhint = nullptr; } else *parent = frame.Self; @@ -487,7 +487,7 @@ ExpressionResult DictExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint try { for (Expression *aexpr : m_Expressions) { - ExpressionResult element = aexpr->Evaluate(frame, m_Inline ? dhint : NULL); + ExpressionResult element = aexpr->Evaluate(frame, m_Inline ? dhint : nullptr); CHECK_RESULT(element); result = element.GetValue(); } @@ -643,7 +643,7 @@ bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value * { Value vparent; String vindex; - DebugHint *psdhint = NULL; + DebugHint *psdhint = nullptr; bool free_psd = false; if (dhint) @@ -674,7 +674,7 @@ bool IndexerExpression::GetReference(ScriptFrame& frame, bool init_dict, Value * if (psdhint) *dhint = new DebugHint(psdhint->GetChild(*index)); else - *dhint = NULL; + *dhint = nullptr; } if (free_psd) @@ -921,7 +921,7 @@ ExpressionResult IncludeExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dh ExpressionResult BreakpointExpression::DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const { - ScriptBreakpoint(frame, NULL, GetDebugInfo()); + ScriptBreakpoint(frame, nullptr, GetDebugInfo()); return Empty; } diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index c5cd197b3..e8046448f 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -200,8 +200,8 @@ class I2_CONFIG_API Expression public: virtual ~Expression(void); - ExpressionResult Evaluate(ScriptFrame& frame, DebugHint *dhint = NULL) const; - virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint = NULL) const; + ExpressionResult Evaluate(ScriptFrame& frame, DebugHint *dhint = nullptr) const; + virtual bool GetReference(ScriptFrame& frame, bool init_dict, Value *parent, String *index, DebugHint **dhint = nullptr) const; virtual const DebugInfo& GetDebugInfo(void) const; virtual ExpressionResult DoEvaluate(ScriptFrame& frame, DebugHint *dhint) const = 0; diff --git a/lib/db_ido/idochecktask.cpp b/lib/db_ido/idochecktask.cpp index b3c11eefd..72ff71bae 100644 --- a/lib/db_ido/idochecktask.cpp +++ b/lib/db_ido/idochecktask.cpp @@ -52,10 +52,10 @@ void IdoCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String idoType = MacroProcessor::ResolveMacros("$ido_type$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); String idoName = MacroProcessor::ResolveMacros("$ido_name$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); if (resolvedMacros && !useResolvedMacros) return; diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index 59be843ea..8b2b52227 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -235,18 +235,18 @@ void IdoMysqlConnection::Reconnect(void) isslCaPath = GetSslCapath(); isslCipher = GetSslCipher(); - host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL; + host = (!ihost.IsEmpty()) ? ihost.CStr() : nullptr; port = GetPort(); - socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : NULL; - user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL; - passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL; - db = (!idb.IsEmpty()) ? idb.CStr() : NULL; - - sslKey = (!isslKey.IsEmpty()) ? isslKey.CStr() : NULL; - sslCert = (!isslCert.IsEmpty()) ? isslCert.CStr() : NULL; - sslCa = (!isslCa.IsEmpty()) ? isslCa.CStr() : NULL; - sslCaPath = (!isslCaPath.IsEmpty()) ? isslCaPath.CStr() : NULL; - sslCipher = (!isslCipher.IsEmpty()) ? isslCipher.CStr() : NULL; + socket_path = (!isocket_path.IsEmpty()) ? isocket_path.CStr() : nullptr; + user = (!iuser.IsEmpty()) ? iuser.CStr() : nullptr; + passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : nullptr; + db = (!idb.IsEmpty()) ? idb.CStr() : nullptr; + + sslKey = (!isslKey.IsEmpty()) ? isslKey.CStr() : nullptr; + sslCert = (!isslCert.IsEmpty()) ? isslCert.CStr() : nullptr; + sslCa = (!isslCa.IsEmpty()) ? isslCa.CStr() : nullptr; + sslCaPath = (!isslCaPath.IsEmpty()) ? isslCaPath.CStr() : nullptr; + sslCipher = (!isslCipher.IsEmpty()) ? isslCipher.CStr() : nullptr; /* connection */ if (!mysql_init(&m_Connection)) { diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index 2db019072..bf71bf5d6 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -210,13 +210,13 @@ void IdoPgsqlConnection::Reconnect(void) ipasswd = GetPassword(); idb = GetDatabase(); - host = (!ihost.IsEmpty()) ? ihost.CStr() : NULL; - port = (!iport.IsEmpty()) ? iport.CStr() : NULL; - user = (!iuser.IsEmpty()) ? iuser.CStr() : NULL; - passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : NULL; - db = (!idb.IsEmpty()) ? idb.CStr() : NULL; + host = (!ihost.IsEmpty()) ? ihost.CStr() : nullptr; + port = (!iport.IsEmpty()) ? iport.CStr() : nullptr; + user = (!iuser.IsEmpty()) ? iuser.CStr() : nullptr; + passwd = (!ipasswd.IsEmpty()) ? ipasswd.CStr() : nullptr; + db = (!idb.IsEmpty()) ? idb.CStr() : nullptr; - m_Connection = PQsetdbLogin(host, port, NULL, NULL, db, user, passwd); + m_Connection = PQsetdbLogin(host, port, nullptr, nullptr, db, user, passwd); if (!m_Connection) return; @@ -508,7 +508,7 @@ String IdoPgsqlConnection::Escape(const String& s) size_t length = utf8s.GetLength(); char *to = new char[utf8s.GetLength() * 2 + 1]; - PQescapeStringConn(m_Connection, to, utf8s.CStr(), length, NULL); + PQescapeStringConn(m_Connection, to, utf8s.CStr(), length, nullptr); String result = String(to); diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index 61a4905a2..03b8296cb 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -67,7 +67,7 @@ void Checkable::UpdateNextCheck(const MessageOrigin::Ptr& origin) { double interval; - if (GetStateType() == StateTypeSoft && GetLastCheckResult() != NULL) + if (GetStateType() == StateTypeSoft && GetLastCheckResult() != nullptr) interval = GetRetryInterval(); else interval = GetCheckInterval(); @@ -85,7 +85,7 @@ void Checkable::UpdateNextCheck(const MessageOrigin::Ptr& origin) bool Checkable::HasBeenChecked(void) const { - return GetLastCheckResult() != NULL; + return GetLastCheckResult() != nullptr; } double Checkable::GetLastCheck(void) const @@ -445,7 +445,7 @@ void Checkable::ExecuteCheck(void) bool local = !endpoint || endpoint == Endpoint::GetLocalEndpoint(); if (local) { - GetCheckCommand()->Execute(this, cr, NULL, false); + GetCheckCommand()->Execute(this, cr, nullptr, false); } else { Dictionary::Ptr macros = new Dictionary(); GetCheckCommand()->Execute(this, cr, macros, false); diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index ca7b479ba..9341e91fa 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -94,7 +94,7 @@ public: void AddGroup(const String& name); - bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr *failedDependency = NULL, int rstack = 0) const; + bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr *failedDependency = nullptr, int rstack = 0) const; AcknowledgementType GetAcknowledgement(void); diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp index 4a831901a..cd59df144 100644 --- a/lib/icinga/legacytimeperiod.cpp +++ b/lib/icinga/legacytimeperiod.cpp @@ -292,7 +292,7 @@ void LegacyTimePeriod::ParseTimeRange(const String& timerange, tm *begin, tm *en String second = def.SubStr(pos + 1).Trim(); - ParseTimeSpec(first, begin, NULL, reference); + ParseTimeSpec(first, begin, nullptr, reference); /* If the second definition starts with a number we need * to add the first word from the first definition, e.g.: @@ -313,7 +313,7 @@ void LegacyTimePeriod::ParseTimeRange(const String& timerange, tm *begin, tm *en second = first.SubStr(0, xpos + 1) + second; } - ParseTimeSpec(second, NULL, end, reference); + ParseTimeSpec(second, nullptr, end, reference); } else { ParseTimeSpec(def, begin, end, reference); } diff --git a/lib/icinga/macroprocessor.cpp b/lib/icinga/macroprocessor.cpp index 570912280..e3d81202f 100644 --- a/lib/icinga/macroprocessor.cpp +++ b/lib/icinga/macroprocessor.cpp @@ -454,7 +454,7 @@ Value MacroProcessor::ResolveArguments(const Value& command, const Dictionary::P { Value resolvedCommand; if (!arguments || command.IsObjectType() || command.IsObjectType()) - resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, NULL, + resolvedCommand = MacroProcessor::ResolveMacros(command, resolvers, cr, nullptr, EscapeMacroShellArg, resolvedMacros, useResolvedMacros, recursionLevel + 1); else { Array::Ptr arr = new Array(); diff --git a/lib/icinga/macroprocessor.hpp b/lib/icinga/macroprocessor.hpp index 0adc5acbc..1b2c015da 100644 --- a/lib/icinga/macroprocessor.hpp +++ b/lib/icinga/macroprocessor.hpp @@ -41,7 +41,7 @@ public: typedef std::vector ResolverList; static Value ResolveMacros(const Value& str, const ResolverList& resolvers, - const CheckResult::Ptr& cr = nullptr, String *missingMacro = NULL, + const CheckResult::Ptr& cr = nullptr, String *missingMacro = nullptr, const EscapeCallback& escapeFn = EscapeCallback(), const Dictionary::Ptr& resolvedMacros = nullptr, bool useResolvedMacros = false, int recursionLevel = 0); diff --git a/lib/icinga/pluginutility.cpp b/lib/icinga/pluginutility.cpp index 15b390a6d..9cb5db8cf 100644 --- a/lib/icinga/pluginutility.cpp +++ b/lib/icinga/pluginutility.cpp @@ -73,7 +73,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab String name = kv.second; Value value = MacroProcessor::ResolveMacros(name, macroResolvers, cr, - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); if (value.IsObjectType()) diff --git a/lib/livestatus/livestatusquery.cpp b/lib/livestatus/livestatusquery.cpp index 71d7402db..5926a0719 100644 --- a/lib/livestatus/livestatusquery.cpp +++ b/lib/livestatus/livestatusquery.cpp @@ -526,7 +526,7 @@ void LivestatusQuery::ExecuteGetHelper(const Stream::Ptr& stream) auto it = allStats.find(statsKey); if (it == allStats.end()) { - std::vector newStats(m_Aggregators.size(), NULL); + std::vector newStats(m_Aggregators.size(), nullptr); it = allStats.insert(std::make_pair(statsKey, newStats)).first; } diff --git a/lib/methods/clrchecktask.cpp b/lib/methods/clrchecktask.cpp index 20640898b..9376fcff2 100644 --- a/lib/methods/clrchecktask.cpp +++ b/lib/methods/clrchecktask.cpp @@ -51,7 +51,7 @@ static void InitializeClr(void) { ICorRuntimeHost *runtimeHost; - if (FAILED(CorBindToRuntimeEx(NULL, NULL, + if (FAILED(CorBindToRuntimeEx(nullptr, nullptr, STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void **)&runtimeHost))) { return; @@ -59,7 +59,7 @@ static void InitializeClr(void) runtimeHost->Start(); - IUnknownPtr punkAppDomain = NULL; + IUnknownPtr punkAppDomain = nullptr; runtimeHost->GetDefaultDomain(&punkAppDomain); punkAppDomain->QueryInterface(__uuidof(mscorlib::_AppDomain), (void **)&l_AppDomain); @@ -87,7 +87,7 @@ static variant_t InvokeClrMethod(const variant_t& vtObject, const String& method HRESULT hr = CLSIDFromProgID(L"System.Collections.Hashtable", &clsid); mscorlib::IDictionaryPtr pHashtable; - CoCreateInstance(clsid, NULL, CLSCTX_ALL, __uuidof(mscorlib::IDictionary), (void **)&pHashtable); + CoCreateInstance(clsid, nullptr, CLSCTX_ALL, __uuidof(mscorlib::IDictionary), (void **)&pHashtable); ObjectLock olock(args); for (const Dictionary::Pair& kv : args) { @@ -107,7 +107,7 @@ static variant_t InvokeClrMethod(const variant_t& vtObject, const String& method variant_t result = pType->InvokeMember_3(methodName.CStr(), mscorlib::BindingFlags_InvokeMethod, - NULL, + nullptr, vtObject, psa); @@ -125,19 +125,19 @@ static void FillCheckResult(const CheckResult::Ptr& cr, variant_t vtResult) SAFEARRAY *psa = SafeArrayCreateVector(VT_VARIANT, 0, 0); int lState = pType->InvokeMember_3("State", mscorlib::BindingFlags_GetField, - NULL, + nullptr, vtResult, psa); cr->SetState(static_cast(lState)); bstr_t sOutput = pType->InvokeMember_3("Output", mscorlib::BindingFlags_GetField, - NULL, + nullptr, vtResult, psa); cr->SetOutput(static_cast(sOutput)); bstr_t sPerformanceData = pType->InvokeMember_3("PerformanceData", mscorlib::BindingFlags_GetField, - NULL, + nullptr, vtResult, psa); SafeArrayDestroy(psa); @@ -171,7 +171,7 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult String name = kv.second; Value value = MacroProcessor::ResolveMacros(name, resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); envMacros->Set(kv.first, value); } @@ -188,9 +188,9 @@ void ClrCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult vtObject = it->second; } else { String clr_assembly = MacroProcessor::ResolveMacros("$clr_assembly$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); String clr_type = MacroProcessor::ResolveMacros("$clr_type$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); if (resolvedMacros && !useResolvedMacros) return; diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 7e240edd9..87cd759ff 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -58,7 +58,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); String zoneName = MacroProcessor::ResolveMacros("$cluster_zone$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); String missingLagWarning; String missingLagCritical; diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index 652ef7e4a..d7f9d3f83 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -50,10 +50,10 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); int dummyState = MacroProcessor::ResolveMacros("$dummy_state$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); String dummyText = MacroProcessor::ResolveMacros("$dummy_text$", resolvers, checkable->GetLastCheckResult(), - NULL, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); + nullptr, MacroProcessor::EscapeCallback(), resolvedMacros, useResolvedMacros); if (resolvedMacros && !useResolvedMacros) return; diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 75ca4008b..213feed13 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -206,9 +206,9 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, String prefix; if (service) { - prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, NULL, std::bind(&GraphiteWriter::EscapeMacroMetric, _1)); + prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, nullptr, std::bind(&GraphiteWriter::EscapeMacroMetric, _1)); } else { - prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, NULL, std::bind(&GraphiteWriter::EscapeMacroMetric, _1)); + prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, nullptr, std::bind(&GraphiteWriter::EscapeMacroMetric, _1)); } String prefixPerfdata = prefix + ".perfdata"; diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 1350edfea..a23827bd3 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -105,7 +105,7 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C resolvers.emplace_back("icinga", IcingaApplication::GetInstance()); if (service) { - String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric); + String line = MacroProcessor::ResolveMacros(GetServiceFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric); { ObjectLock olock(this); @@ -115,7 +115,7 @@ void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C m_ServiceOutputFile << line << "\n"; } } else { - String line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr, NULL, &PerfdataWriter::EscapeMacroMetric); + String line = MacroProcessor::ResolveMacros(GetHostFormatTemplate(), resolvers, cr, nullptr, &PerfdataWriter::EscapeMacroMetric); { ObjectLock olock(this); diff --git a/lib/remote/configobjectutility.cpp b/lib/remote/configobjectutility.cpp index 09344a4f9..fd1afc1e8 100644 --- a/lib/remote/configobjectutility.cpp +++ b/lib/remote/configobjectutility.cpp @@ -132,7 +132,7 @@ bool ConfigObjectUtility::CreateObject(const Type::Ptr& type, const String& full ScriptFrame frame; expr->Evaluate(frame); delete expr; - expr = NULL; + expr = nullptr; WorkQueue upq; std::vector newItems; diff --git a/lib/remote/consolehandler.cpp b/lib/remote/consolehandler.cpp index 9004a57ae..ed2748c3a 100644 --- a/lib/remote/consolehandler.cpp +++ b/lib/remote/consolehandler.cpp @@ -123,7 +123,7 @@ bool ConsoleHandler::ExecuteScriptHelper(HttpRequest& request, HttpResponse& res Array::Ptr results = new Array(); Dictionary::Ptr resultInfo = new Dictionary(); - Expression *expr = NULL; + Expression *expr = nullptr; Value exprResult; try { diff --git a/lib/remote/eventqueue.cpp b/lib/remote/eventqueue.cpp index 5681214a2..e7b0b4bf9 100644 --- a/lib/remote/eventqueue.cpp +++ b/lib/remote/eventqueue.cpp @@ -25,7 +25,7 @@ using namespace icinga; EventQueue::EventQueue(const String& name) - : m_Name(name), m_Filter(NULL) + : m_Name(name), m_Filter(nullptr) { } EventQueue::~EventQueue(void) diff --git a/lib/remote/eventshandler.cpp b/lib/remote/eventshandler.cpp index e27b136d2..c8c57c6b5 100644 --- a/lib/remote/eventshandler.cpp +++ b/lib/remote/eventshandler.cpp @@ -66,7 +66,7 @@ bool EventsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request String filter = HttpUtility::GetLastParameter(params, "filter"); - Expression *ufilter = NULL; + Expression *ufilter = nullptr; if (!filter.IsEmpty()) ufilter = ConfigCompiler::CompileText("", filter); diff --git a/lib/remote/filterutility.cpp b/lib/remote/filterutility.cpp index 8038314d6..672d3afe5 100644 --- a/lib/remote/filterutility.cpp +++ b/lib/remote/filterutility.cpp @@ -133,7 +133,7 @@ static void FilteredAddTarget(ScriptFrame& permissionFrame, Expression *permissi void FilterUtility::CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **permissionFilter) { if (permissionFilter) - *permissionFilter = NULL; + *permissionFilter = nullptr; if (permission.IsEmpty()) return; @@ -250,7 +250,7 @@ std::vector FilterUtility::GetFilterTargets(const QueryDescription& qd, c frame.Sandboxed = true; Dictionary::Ptr uvars = new Dictionary(); - Expression *ufilter = NULL; + Expression *ufilter = nullptr; if (query->Contains("filter")) { String filter = HttpUtility::GetLastParameter(query, "filter"); diff --git a/lib/remote/filterutility.hpp b/lib/remote/filterutility.hpp index 461cfd638..6b06def31 100644 --- a/lib/remote/filterutility.hpp +++ b/lib/remote/filterutility.hpp @@ -68,7 +68,7 @@ class I2_REMOTE_API FilterUtility { public: static Type::Ptr TypeFromPluralName(const String& pluralName); - static void CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **filter = NULL); + static void CheckPermission(const ApiUser::Ptr& user, const String& permission, Expression **filter = nullptr); static std::vector GetFilterTargets(const QueryDescription& qd, const Dictionary::Ptr& query, const ApiUser::Ptr& user, const String& variableName = String()); static bool EvaluateFilter(ScriptFrame& frame, Expression *filter, diff --git a/lib/remote/httprequest.cpp b/lib/remote/httprequest.cpp index a1be4bd45..82f144dd3 100644 --- a/lib/remote/httprequest.cpp +++ b/lib/remote/httprequest.cpp @@ -226,7 +226,7 @@ void HttpRequest::Finish(void) if (m_State == HttpRequestStart || m_State == HttpRequestHeaders) FinishHeaders(); - WriteBody(NULL, 0); + WriteBody(nullptr, 0); m_Stream->Write("\r\n", 2); } diff --git a/lib/remote/httpresponse.cpp b/lib/remote/httpresponse.cpp index 308cbd272..e8b1b7061 100644 --- a/lib/remote/httpresponse.cpp +++ b/lib/remote/httpresponse.cpp @@ -108,7 +108,7 @@ void HttpResponse::Finish(void) m_Stream->Write(buffer, rc); } } else { - WriteBody(NULL, 0); + WriteBody(nullptr, 0); m_Stream->Write("\r\n", 2); } diff --git a/lib/remote/pkiutility.cpp b/lib/remote/pkiutility.cpp index 0457b6ed0..3aa5006ff 100644 --- a/lib/remote/pkiutility.cpp +++ b/lib/remote/pkiutility.cpp @@ -71,7 +71,7 @@ int PkiUtility::SignCsr(const String& csrfile, const String& certfile) InitializeOpenSSL(); BIO *csrbio = BIO_new_file(csrfile.CStr(), "r"); - X509_REQ *req = PEM_read_bio_X509_REQ(csrbio, NULL, NULL, NULL); + X509_REQ *req = PEM_read_bio_X509_REQ(csrbio, nullptr, nullptr, nullptr); if (!req) { Log(LogCritical, "SSL") @@ -396,7 +396,7 @@ static void CollectRequestHandler(const Dictionary::Ptr& requests, const String& /* XXX (requires OpenSSL >= 1.0.0) time_t now; time(&now); - ASN1_TIME *tm = ASN1_TIME_adj(NULL, now, 0, 0); + ASN1_TIME *tm = ASN1_TIME_adj(nullptr, now, 0, 0); int day, sec; ASN1_TIME_diff(&day, &sec, tm, X509_get_notBefore(certRequest.get())); diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 6da89cd56..97b342de9 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -226,7 +226,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) << "{" << std::endl << "\t" << "static ObjectFactory GetFactory(void)" << std::endl << "\t" << "{" << std::endl - << "\t\t" << "return NULL;" << std::endl + << "\t\t" << "return nullptr;" << std::endl << "\t" << "}" << std::endl << "};" << std::endl << std::endl; } @@ -374,7 +374,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) if (field.Type.IsName) nameref = "\"" + field.Type.TypeName + "\""; else - nameref = "NULL"; + nameref = "nullptr"; m_Impl << "\t\t" << "case " << num << ":" << std::endl << "\t\t\t" << "return Field(" << num << ", \"" << ftype << "\", \"" << field.Name << "\", \"" << (field.NavigationName.empty() ? field.Name : field.NavigationName) << "\", " << nameref << ", " << field.Attributes << ", " << field.Type.ArrayRank << ");" << std::endl; @@ -1411,7 +1411,7 @@ std::string ClassCompiler::BaseName(const std::string& path) char *dir = strdup(path.c_str()); std::string result; - if (dir == NULL) + if (!dir) throw std::bad_alloc(); #ifndef _WIN32