From: Mikko Rasa Date: Sun, 31 Oct 2021 17:09:29 +0000 (+0200) Subject: Use nullptr instead of 0 for pointers X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=commitdiff_plain;h=41363aed34382386f915f17c1a961750b4fdcb14 Use nullptr instead of 0 for pointers --- diff --git a/examples/z.cpp b/examples/z.cpp index d98392c..5f793c4 100644 --- a/examples/z.cpp +++ b/examples/z.cpp @@ -24,7 +24,7 @@ public: }; Z::Z(int argc, char **argv): - input_file(0) + input_file(nullptr) { string input_fn; GetOpt getopt; diff --git a/source/core/android/main.cpp b/source/core/android/main.cpp index a71d92f..ff811c1 100644 --- a/source/core/android/main.cpp +++ b/source/core/android/main.cpp @@ -2,7 +2,7 @@ extern "C" void ANativeActivity_onCreate(ANativeActivity *activity, void * /*saved_state*/, size_t /*state_size*/) { - static Msp::Android::MainThread *thread = 0; + static Msp::Android::MainThread *thread = nullptr; if(thread) thread->attach_to_activity(activity); else diff --git a/source/core/android/mainthread.cpp b/source/core/android/mainthread.cpp index b816bf6..6441c20 100644 --- a/source/core/android/mainthread.cpp +++ b/source/core/android/mainthread.cpp @@ -53,7 +53,7 @@ void MainThread::resume_startup() JavaVM *MainThread::get_java_vm() const { if(!activity) - return 0; + return nullptr; return activity->vm; } @@ -68,7 +68,7 @@ void MainThread::main() /* I have no idea how dependable this is, but it seems to be the only way to get the package name aside from making a Java call through JNI */ char *appname = strdup(int_data_path[-2].c_str()); - char *argv[] = { appname, 0 }; + char *argv[] = { appname, nullptr }; Msp::Android::ErrorLogger err_logger; FS::chdir(FS::dirname(int_data_path)); Msp::Application::run(1, argv, this, &app_created); diff --git a/source/core/android/mainthread.h b/source/core/android/mainthread.h index 99a641b..9ce9428 100644 --- a/source/core/android/mainthread.h +++ b/source/core/android/mainthread.h @@ -20,8 +20,8 @@ public: sigc::signal signal_input_queue_destroyed; private: - ANativeActivity *activity = 0; - AAssetManager *asset_manager = 0; + ANativeActivity *activity = nullptr; + AAssetManager *asset_manager = nullptr; FS::Path int_data_path; bool starting_up = true; Mutex startup_mutex; diff --git a/source/core/application.cpp b/source/core/application.cpp index 1fbe154..8447eed 100644 --- a/source/core/application.cpp +++ b/source/core/application.cpp @@ -15,11 +15,11 @@ using namespace std; namespace Msp { -Application *Application::_app = 0; -Application::Starter *Application::_starter = 0; -const char *Application::_argv0 = 0; +Application *Application::_app = nullptr; +Application::Starter *Application::_starter = nullptr; +const char *Application::_argv0 = nullptr; string Application::_name; -void *Application::_data = 0; +void *Application::_data = nullptr; Application::Application(const string &n) { @@ -59,7 +59,7 @@ int Application::run(int argc, char **argv, void *data, void (*created_callback) int result = _app->main(); Application *a = _app; - _app = 0; + _app = nullptr; delete a; return result; } @@ -85,7 +85,7 @@ int Application::run(int argc, char **argv, void *data, void (*created_callback) } delete _app; - _app = 0; + _app = nullptr; return 124; } diff --git a/source/core/application.h b/source/core/application.h index c3c693d..972f3b7 100644 --- a/source/core/application.h +++ b/source/core/application.h @@ -44,7 +44,7 @@ public: This function can only be called once. The global main() function provided by the library normally does it automatically at program startup. */ - static int run(int, char **, void * = 0, void (*)(void *) = 0); + static int run(int, char **, void * = nullptr, void (*)(void *) = nullptr); /** Sets application startup info, including argv[0] value and platform- specific data. diff --git a/source/core/getopt.h b/source/core/getopt.h index ed6cf86..ade620b 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -121,10 +121,10 @@ private: std::string lng; ArgType arg_type = NO_ARG; unsigned seen_count = 0; - unsigned *ext_seen_count = 0; + unsigned *ext_seen_count = nullptr; std::string help; std::string metavar = "ARG"; - Store *store = 0; + Store *store = nullptr; public: OptionImpl(char, const std::string &, const Store &, ArgType); @@ -149,7 +149,7 @@ private: std::string name; ArgType type = REQUIRED_ARG; std::string help; - Store *store = 0; + Store *store = nullptr; public: ArgumentImpl(const std::string &, const Store &, ArgType); diff --git a/source/core/module.h b/source/core/module.h index 339af08..4b1e3e8 100644 --- a/source/core/module.h +++ b/source/core/module.h @@ -11,7 +11,7 @@ class Module: private NonCopyable private: struct Private; - Private *priv = 0; + Private *priv = nullptr; public: Module(const std::string &); diff --git a/source/core/mutex.h b/source/core/mutex.h index dc9a228..6582074 100644 --- a/source/core/mutex.h +++ b/source/core/mutex.h @@ -17,7 +17,7 @@ class Mutex: private NonCopyable private: struct Private; - Private *priv = 0; + Private *priv = nullptr; public: Mutex(); @@ -67,7 +67,7 @@ public: T &operator*() const { return *data; } T *operator->() const { return data; } - void clear() { mutex = 0; data = 0; } + void clear() { mutex = nullptr; data = nullptr; } }; } diff --git a/source/core/osx/main.cpp b/source/core/osx/main.cpp index e9a6fe2..4bb81c8 100644 --- a/source/core/osx/main.cpp +++ b/source/core/osx/main.cpp @@ -3,7 +3,7 @@ int main(int argc, char **argv) { - void *data = 0; + void *data = nullptr; /* Applications launched from Finder get a special argument, which would interfere with GetOpt. Remove it from argv but pass it as data so it can @@ -17,7 +17,7 @@ int main(int argc, char **argv) argv[j++] = argv[i]; } argc = j; - argv[j] = 0; + argv[j] = nullptr; return Msp::Application::run(argc, argv, data); } diff --git a/source/core/process.cpp b/source/core/process.cpp index 92475d4..43b7384 100644 --- a/source/core/process.cpp +++ b/source/core/process.cpp @@ -6,7 +6,7 @@ using namespace std; namespace Msp { -Process *Process::_self = 0; +Process *Process::_self = nullptr; Process::Process(const Private &p): priv(new Private(p)) diff --git a/source/core/process.h b/source/core/process.h index f21ecb3..0d7faa6 100644 --- a/source/core/process.h +++ b/source/core/process.h @@ -30,12 +30,12 @@ public: private: struct Private; - Private *priv = 0; + Private *priv = nullptr; FS::Path work_dir; bool redirect = false; - IO::Base *cin = 0; - IO::Base *cout = 0; - IO::Base *cerr = 0; + IO::Base *cin = nullptr; + IO::Base *cout = nullptr; + IO::Base *cerr = nullptr; bool running = false; bool finished = false; unsigned exit_code = 0; diff --git a/source/core/refptr.h b/source/core/refptr.h index 70cb176..34560ec 100644 --- a/source/core/refptr.h +++ b/source/core/refptr.h @@ -31,14 +31,14 @@ class RefPtr template friend class WeakPtr; private: - T *data = 0; - RefCounts *counts = 0; + T *data = nullptr; + RefCounts *counts = nullptr; public: RefPtr() = default; - RefPtr(T *d): data(d), counts(data ? new RefCounts : 0) { incref(); } + RefPtr(T *d): data(d), counts(data ? new RefCounts : nullptr) { incref(); } private: - RefPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } + RefPtr(T *d, RefCounts *c): data(d), counts(d ? c : nullptr) { incref(); } public: /* Must have this or the compiler will generate a default copy-c'tor despite @@ -49,7 +49,7 @@ public: RefPtr(const RefPtr &p): data(p.data), counts(p.counts) { incref(); } template - RefPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : 0) { incref(); } + RefPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : nullptr) { incref(); } ~RefPtr() { decref(); } @@ -81,7 +81,7 @@ public: T *get() const { return data; } T &operator*() const { return *data; } T *operator->() const { return data; } - explicit operator bool() const { return data!=0; } + explicit operator bool() const { return data; } unsigned refcount() const { return (data ? counts->count : 0); } @@ -102,19 +102,19 @@ class WeakPtr template friend class WeakPtr; private: - T *data = 0; - RefCounts *counts = 0; + T *data = nullptr; + RefCounts *counts = nullptr; public: WeakPtr() = default; private: - WeakPtr(T *d, RefCounts *c): data(d), counts(d ? c : 0) { incref(); } + WeakPtr(T *d, RefCounts *c): data(d), counts(d ? c : nullptr) { incref(); } public: - WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : 0) { incref(); } + WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : nullptr) { incref(); } template - WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : 0) { incref(); } + WeakPtr(const WeakPtr &p): data(p.get()), counts(data ? p.counts : nullptr) { incref(); } template WeakPtr(const RefPtr &p): data(p.data), counts(p.counts) { incref(); } @@ -131,7 +131,7 @@ private: template WeakPtr &assign(const WeakPtr &); - T *get() const { return (counts && counts->count ? data : 0); } + T *get() const { return (counts && counts->count ? data : nullptr); } void incref() { if(counts) ++counts->weak_count; } void decref(); }; @@ -142,7 +142,7 @@ RefPtr &RefPtr::operator=(T *d) { decref(); data = d; - counts = (d ? new RefCounts : 0); + counts = (d ? new RefCounts : nullptr); incref(); return *this; } @@ -162,9 +162,9 @@ template T *RefPtr::release() { T *d = data; - data = 0; + data = nullptr; decref(); - counts = 0; + counts = nullptr; return d; } @@ -176,17 +176,17 @@ void RefPtr::decref() if(!counts->count) { delete data; - data = 0; + data = nullptr; } else if(counts->count==RefCounts::KEEP) - data = 0; + data = nullptr; else return; if(!counts->weak_count) { delete counts; - counts = 0; + counts = nullptr; } } @@ -197,7 +197,7 @@ WeakPtr &WeakPtr::assign(const WeakPtr &p) { decref(); data = p.get(); - counts = (data ? p.counts : 0); + counts = (data ? p.counts : nullptr); incref(); return *this; } @@ -210,8 +210,8 @@ void WeakPtr::decref() if(!counts->weak_count && (!counts->count || counts->count==RefCounts::KEEP)) { delete counts; - data = 0; - counts = 0; + data = nullptr; + counts = nullptr; } } diff --git a/source/core/semaphore.h b/source/core/semaphore.h index 4b22945..28c3b3d 100644 --- a/source/core/semaphore.h +++ b/source/core/semaphore.h @@ -11,7 +11,7 @@ class Semaphore: private NonCopyable private: struct Private; - Private *priv = 0; + Private *priv = nullptr; public: Semaphore(unsigned); diff --git a/source/core/thread.cpp b/source/core/thread.cpp index 841cc3f..e860d67 100644 --- a/source/core/thread.cpp +++ b/source/core/thread.cpp @@ -51,7 +51,7 @@ ThreadReturn THREAD_CALL Thread::Private::main_wrapper(void *arg) thread->platform_setname(); thread->main(); thread->_state = FINISHED; - return 0; + return nullptr; } } // namespace Msp diff --git a/source/core/thread.h b/source/core/thread.h index ae9a0dd..ef071cd 100644 --- a/source/core/thread.h +++ b/source/core/thread.h @@ -27,7 +27,7 @@ private: JOINED }; - Private *_priv = 0; + Private *_priv = nullptr; std::string _name; State _state = PENDING; diff --git a/source/core/unix/main.cpp b/source/core/unix/main.cpp index 434dba1..58c9fda 100644 --- a/source/core/unix/main.cpp +++ b/source/core/unix/main.cpp @@ -2,5 +2,5 @@ int main(int argc, char **argv) { - return Msp::Application::run(argc, argv, 0); + return Msp::Application::run(argc, argv, nullptr); } diff --git a/source/core/unix/mutex.cpp b/source/core/unix/mutex.cpp index 15e5c9a..a23add5 100644 --- a/source/core/unix/mutex.cpp +++ b/source/core/unix/mutex.cpp @@ -9,7 +9,7 @@ namespace Msp { Mutex::Mutex(): priv(new Private) { - pthread_mutex_init(&priv->mutex, 0); + pthread_mutex_init(&priv->mutex, nullptr); } Mutex::~Mutex() diff --git a/source/core/unix/process.cpp b/source/core/unix/process.cpp index 99be2e1..7370b70 100644 --- a/source/core/unix/process.cpp +++ b/source/core/unix/process.cpp @@ -35,7 +35,7 @@ void Process::execute(const string &command, bool path_search, const Arguments & argv[0] = command.c_str(); for(unsigned i=0; icond, 0); + pthread_cond_init(&priv->cond, nullptr); priv->limit = limit; } diff --git a/source/core/unix/thread.cpp b/source/core/unix/thread.cpp index 1ddcaae..4223193 100644 --- a/source/core/unix/thread.cpp +++ b/source/core/unix/thread.cpp @@ -7,7 +7,7 @@ namespace Msp { void Thread::platform_join() { - pthread_join(_priv->handle, 0); + pthread_join(_priv->handle, nullptr); } void Thread::platform_kill() @@ -17,7 +17,7 @@ void Thread::platform_kill() void Thread::platform_launch() { - pthread_create(&_priv->handle, 0, &Private::main_wrapper, this); + pthread_create(&_priv->handle, nullptr, &Private::main_wrapper, this); } void Thread::platform_setname() diff --git a/source/core/variant.h b/source/core/variant.h index 2e9caaf..443befb 100644 --- a/source/core/variant.h +++ b/source/core/variant.h @@ -50,13 +50,13 @@ private: { return false; } }; - StoreBase *store = 0; + StoreBase *store = nullptr; public: Variant() = default; template Variant(const T &v): store(new Store::type>(v)) { } - Variant(const Variant &v): store(v.store ? v.store->clone() : 0) { } + Variant(const Variant &v): store(v.store ? v.store->clone() : nullptr) { } ~Variant() { delete store; } template @@ -70,7 +70,7 @@ public: Variant &operator=(const Variant &v) { delete store; - store = (v.store ? v.store->clone() : 0); + store = (v.store ? v.store->clone() : nullptr); return *this; } @@ -101,7 +101,7 @@ public: template bool check_type() const { - return dynamic_cast::type> *>(store)!=0; + return dynamic_cast::type> *>(store); } bool check_same_type(const Variant &v) const diff --git a/source/core/windows/process.cpp b/source/core/windows/process.cpp index 8293650..3bd03fa 100644 --- a/source/core/windows/process.cpp +++ b/source/core/windows/process.cpp @@ -48,7 +48,7 @@ Process::~Process() void Process::platform_get_self_info(Private &priv) { priv.info.hProcess = GetCurrentProcess(); - priv.info.hThread = 0; + priv.info.hThread = nullptr; priv.info.dwProcessId = GetCurrentProcessId(); priv.info.dwThreadId = 0; } @@ -61,12 +61,12 @@ void Process::execute(const string &command, bool path_search, const Arguments & STARTUPINFO startup; startup.cb = sizeof(STARTUPINFO); - startup.lpReserved = 0; - startup.lpDesktop = 0; - startup.lpTitle = 0; + startup.lpReserved = nullptr; + startup.lpDesktop = nullptr; + startup.lpTitle = nullptr; startup.dwFlags = 0; startup.cbReserved2 = 0; - startup.lpReserved2 = 0; + startup.lpReserved2 = nullptr; if(redirect) { startup.dwFlags |= STARTF_USESTDHANDLES; @@ -78,9 +78,9 @@ void Process::execute(const string &command, bool path_search, const Arguments & HANDLE cerr_handle = (cerr ? *cerr->get_handle(IO::M_WRITE) : GetStdHandle(STD_ERROR_HANDLE)); DuplicateHandle(self_handle, cerr_handle, self_handle, &startup.hStdError, 0, true, DUPLICATE_SAME_ACCESS); } - const char *cmdptr = (path_search ? 0 : command.c_str()); - const char *wd = (work_dir.empty() ? 0 : work_dir.c_str()); - if(!CreateProcess(cmdptr, const_cast(cmdline.c_str()), 0, 0, true, 0, 0, wd, &startup, &priv->info)) + const char *cmdptr = (path_search ? nullptr : command.c_str()); + const char *wd = (work_dir.empty() ? nullptr : work_dir.c_str()); + if(!CreateProcess(cmdptr, const_cast(cmdline.c_str()), nullptr, nullptr, true, 0, nullptr, wd, &startup, &priv->info)) throw system_error("CreateProcess"); if(redirect) @@ -135,8 +135,8 @@ void Process::interrupt() Process::Private::Private() { - info.hProcess = 0; - info.hThread = 0; + info.hProcess = nullptr; + info.hThread = nullptr; info.dwProcessId = 0; info.dwThreadId = 0; } diff --git a/source/core/windows/systemerror.cpp b/source/core/windows/systemerror.cpp index 98eb9ed..93aa7bd 100644 --- a/source/core/windows/systemerror.cpp +++ b/source/core/windows/systemerror.cpp @@ -11,7 +11,7 @@ string system_error::get_message(int c) c = GetLastError(); char msg[1024]; - if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, c, 0, msg, sizeof(msg), 0)) + if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, c, 0, msg, sizeof(msg), nullptr)) return msg; else return lexical_cast(c, Fmt().hex()); diff --git a/source/core/windows/thread.cpp b/source/core/windows/thread.cpp index 2483094..8890a70 100644 --- a/source/core/windows/thread.cpp +++ b/source/core/windows/thread.cpp @@ -17,7 +17,7 @@ void Thread::platform_kill() void Thread::platform_launch() { DWORD dummy; // Win9x needs the lpTthreadId parameter - _priv->handle = CreateThread(0, 0, &Private::main_wrapper, this, 0, &dummy); + _priv->handle = CreateThread(nullptr, 0, &Private::main_wrapper, this, 0, &dummy); } void Thread::platform_setname() diff --git a/source/debug/backtrace.h b/source/debug/backtrace.h index 67cf62f..98aa4d8 100644 --- a/source/debug/backtrace.h +++ b/source/debug/backtrace.h @@ -13,7 +13,7 @@ class Backtrace public: struct StackFrame { - void *address = 0; + void *address = nullptr; std::string file; std::string symbol; }; diff --git a/source/debug/demangle.cpp b/source/debug/demangle.cpp index e41eb9a..3ed3171 100644 --- a/source/debug/demangle.cpp +++ b/source/debug/demangle.cpp @@ -13,7 +13,7 @@ string demangle(const string &sym) { #ifdef __GNUC__ int status; - char *dm = abi::__cxa_demangle(sym.c_str(), 0, 0, &status); + char *dm = abi::__cxa_demangle(sym.c_str(), nullptr, nullptr, &status); string result; if(status==0) diff --git a/source/debug/errorreporter.cpp b/source/debug/errorreporter.cpp index 8f080a3..edfa002 100644 --- a/source/debug/errorreporter.cpp +++ b/source/debug/errorreporter.cpp @@ -3,7 +3,7 @@ namespace Msp { namespace Debug { -ErrorReporter *ErrorReporter::_current = 0; +ErrorReporter *ErrorReporter::_current = nullptr; ErrorReporter::ErrorReporter(): _prev(_current) diff --git a/source/debug/errorreporter.h b/source/debug/errorreporter.h index dca8f52..9a60f85 100644 --- a/source/debug/errorreporter.h +++ b/source/debug/errorreporter.h @@ -10,7 +10,7 @@ namespace Debug { class ErrorReporter: private NonCopyable { private: - ErrorReporter *_prev = 0; + ErrorReporter *_prev = nullptr; static ErrorReporter *_current; diff --git a/source/debug/exceptiontrace.cpp b/source/debug/exceptiontrace.cpp index 8ffc9c8..7a681c3 100644 --- a/source/debug/exceptiontrace.cpp +++ b/source/debug/exceptiontrace.cpp @@ -20,7 +20,7 @@ struct HookThrow HookThrow::HookThrow() { - void *handle = dlopen(0, RTLD_LAZY); + void *handle = dlopen(nullptr, RTLD_LAZY); orig_cxa_throw = reinterpret_cast(dlvsym(handle, "__cxa_throw", "CXXABI_1.3")); dlclose(handle); } diff --git a/source/debug/profiler.h b/source/debug/profiler.h index 5018c7f..22d2c9a 100644 --- a/source/debug/profiler.h +++ b/source/debug/profiler.h @@ -51,7 +51,7 @@ public: private: unsigned period = 0; std::map scopes; - ProfilingScope *inner = 0; + ProfilingScope *inner = nullptr; public: /** Sets the averaging period for timing data, measured in calls. Previous diff --git a/source/debug/profilingscope.h b/source/debug/profilingscope.h index 69d1c49..586efa3 100644 --- a/source/debug/profilingscope.h +++ b/source/debug/profilingscope.h @@ -18,7 +18,7 @@ class ProfilingScope: private NonCopyable private: Profiler &profiler; std::string name; - ProfilingScope *parent = 0; + ProfilingScope *parent = nullptr; Time::TimeStamp entry_time; Time::TimeDelta time_spent; Time::TimeDelta child_time; diff --git a/source/fs/filemonitor.cpp b/source/fs/filemonitor.cpp index a1b713b..5ab3f49 100644 --- a/source/fs/filemonitor.cpp +++ b/source/fs/filemonitor.cpp @@ -19,7 +19,7 @@ FileMonitor::~FileMonitor() void FileMonitor::use_event_dispatcher(IO::EventDispatcher &ed) { if(event_disp) - throw logic_error("event_disp!=0"); + throw logic_error("event_disp!=nullptr"); event_disp = &ed; platform_use_event_dispatcher(); diff --git a/source/fs/filemonitor.h b/source/fs/filemonitor.h index 9e72ad2..411cb21 100644 --- a/source/fs/filemonitor.h +++ b/source/fs/filemonitor.h @@ -25,8 +25,8 @@ public: sigc::signal signal_file_modified; private: - Private *priv = 0; - IO::EventDispatcher *event_disp = 0; + Private *priv = nullptr; + IO::EventDispatcher *event_disp = nullptr; std::vector files; public: diff --git a/source/fs/stat.cpp b/source/fs/stat.cpp index ae9f803..773cdef 100644 --- a/source/fs/stat.cpp +++ b/source/fs/stat.cpp @@ -14,7 +14,7 @@ Stat::Stat(const Stat &other): alloc_size(other.alloc_size), mtime(other.mtime), owner_info(other.owner_info), - priv(other.priv ? new Private(*other.priv) : 0) + priv(other.priv ? new Private(*other.priv) : nullptr) { } Stat &Stat::operator=(const Stat &other) @@ -26,7 +26,7 @@ Stat &Stat::operator=(const Stat &other) mtime = other.mtime; owner_info = other.owner_info; delete priv; - priv = (other.priv ? new Private(*other.priv) : 0); + priv = (other.priv ? new Private(*other.priv) : nullptr); return *this; } diff --git a/source/fs/stat.h b/source/fs/stat.h index d23a8e8..c32e879 100644 --- a/source/fs/stat.h +++ b/source/fs/stat.h @@ -39,7 +39,7 @@ private: FileSize alloc_size = 0; Time::TimeStamp mtime; mutable OwnerInfo owner_info; - Private *priv = 0; + Private *priv = nullptr; public: Stat() = default; diff --git a/source/fs/windows/dir.cpp b/source/fs/windows/dir.cpp index c6f6b9b..fde0200 100644 --- a/source/fs/windows/dir.cpp +++ b/source/fs/windows/dir.cpp @@ -28,7 +28,7 @@ vector list_filtered(const Path &path, const string &filter) vector result; WIN32_FIND_DATA entry; string pattern = path.str()+"\\*"; - HANDLE search_handle = FindFirstFileEx(pattern.c_str(), FindExInfoBasic, &entry, FindExSearchNameMatch, 0, 0); + HANDLE search_handle = FindFirstFileEx(pattern.c_str(), FindExInfoBasic, &entry, FindExSearchNameMatch, nullptr, 0); if(search_handle==INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); diff --git a/source/fs/windows/dir_location.cpp b/source/fs/windows/dir_location.cpp index 4c3b866..4f9b8f6 100644 --- a/source/fs/windows/dir_location.cpp +++ b/source/fs/windows/dir_location.cpp @@ -10,7 +10,7 @@ namespace FS { Path get_home_dir() { char home[MAX_PATH]; - if(SHGetFolderPath(0, CSIDL_PERSONAL, 0, 0, home)==S_OK) + if(SHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, 0, home)==S_OK) return home; return "."; } @@ -22,7 +22,7 @@ Path get_user_data_dir() throw logic_error("no application name"); char datadir[MAX_PATH]; - if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK) + if(SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, datadir)==S_OK) return Path(datadir)/appname; return "."; } diff --git a/source/fs/windows/stat.cpp b/source/fs/windows/stat.cpp index 36f28a0..8331e60 100644 --- a/source/fs/windows/stat.cpp +++ b/source/fs/windows/stat.cpp @@ -13,7 +13,7 @@ namespace { PSID copy_sid(PSID sid) { if(!sid || !IsValidSid(sid)) - return 0; + return nullptr; DWORD len = GetLengthSid(sid); PSID copy = reinterpret_cast(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len)); if(!CopySid(len, copy, sid)) @@ -32,7 +32,7 @@ string get_account_name(PSID sid) char domain[1024]; DWORD dlen = sizeof(domain); SID_NAME_USE use; - if(!LookupAccountSid(0, sid, name, &nlen, domain, &dlen, &use)) + if(!LookupAccountSid(nullptr, sid, name, &nlen, domain, &dlen, &use)) throw Msp::system_error("LookupAccountSid"); return Msp::format("%s/%s", name, domain); } @@ -73,7 +73,7 @@ void Stat::Private::fill_owner_info(Stat::OwnerInfo &result) Stat Stat::stat(const Path &path) { HANDLE handle; - handle = CreateFile(path.str().c_str(), READ_CONTROL, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, 0); + handle = CreateFile(path.str().c_str(), READ_CONTROL, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, nullptr); if(handle==INVALID_HANDLE_VALUE) { DWORD err = GetLastError(); @@ -102,10 +102,10 @@ Stat Stat::stat(const Path &path) result.mtime = Time::TimeStamp(Time::filetime_to_rawtime(info.ftLastWriteTime)); PSECURITY_DESCRIPTOR sec_desc; - PSID owner = 0; - PSID group = 0; + PSID owner = nullptr; + PSID group = nullptr; const SECURITY_INFORMATION sec_info = OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION; - DWORD err = GetSecurityInfo(handle, SE_FILE_OBJECT, sec_info, &owner, &group, 0, 0, &sec_desc); + DWORD err = GetSecurityInfo(handle, SE_FILE_OBJECT, sec_info, &owner, &group, nullptr, nullptr, &sec_desc); if(err) { CloseHandle(handle); diff --git a/source/fs/windows/stat_platform.h b/source/fs/windows/stat_platform.h index c193acc..6440aca 100644 --- a/source/fs/windows/stat_platform.h +++ b/source/fs/windows/stat_platform.h @@ -9,8 +9,8 @@ namespace FS { typedef PSID UserID; typedef PSID GroupID; -const UserID INVALID_UID = 0; -const GroupID INVALID_GID = 0; +const UserID INVALID_UID = nullptr; +const GroupID INVALID_GID = nullptr; } // namespace FS } // namespace Msp diff --git a/source/io/asset.h b/source/io/asset.h index 23a110e..d59db94 100644 --- a/source/io/asset.h +++ b/source/io/asset.h @@ -16,7 +16,7 @@ class Asset: public Seekable private: struct Private; - Private *priv = 0; + Private *priv = nullptr; public: Asset(const std::string &); diff --git a/source/io/base.h b/source/io/base.h index 1a1485e..aadc6ac 100644 --- a/source/io/base.h +++ b/source/io/base.h @@ -44,7 +44,7 @@ public: protected: Mode mode = M_READ; bool eof_flag = false; - Mutex *mutex = 0; + Mutex *mutex = nullptr; Base(); public: diff --git a/source/io/buffered.h b/source/io/buffered.h index 39c8159..a5f6348 100644 --- a/source/io/buffered.h +++ b/source/io/buffered.h @@ -12,9 +12,9 @@ class Buffered: public Base, public sigc::trackable private: Base &below; std::size_t buf_size = 0; - char *buf = 0; - char *begin = 0; - char *end = 0; + char *buf = nullptr; + char *begin = nullptr; + char *end = nullptr; Mode cur_op = M_NONE; public: diff --git a/source/io/eventreader.h b/source/io/eventreader.h index 51785b0..c4ae56b 100644 --- a/source/io/eventreader.h +++ b/source/io/eventreader.h @@ -25,7 +25,7 @@ private: struct Private; Handle &handle; - Private *priv = 0; + Private *priv = nullptr; public: EventReader(Handle &, unsigned); diff --git a/source/io/handle.h b/source/io/handle.h index 561d710..6140e11 100644 --- a/source/io/handle.h +++ b/source/io/handle.h @@ -12,7 +12,7 @@ public: struct Private; private: - Private *priv = 0; + Private *priv = nullptr; public: Handle(); diff --git a/source/io/memory.h b/source/io/memory.h index 0486567..c24d3f7 100644 --- a/source/io/memory.h +++ b/source/io/memory.h @@ -9,9 +9,9 @@ namespace IO { class Memory: public Seekable { private: - char *begin = 0; - char *end = 0; - char *pos = 0; + char *begin = nullptr; + char *end = nullptr; + char *pos = nullptr; public: Memory(char *d, std::size_t s, Mode m = M_RDWR): Memory(d, d+s, m) { } diff --git a/source/io/poll.h b/source/io/poll.h index ca0b0b7..c873923 100644 --- a/source/io/poll.h +++ b/source/io/poll.h @@ -36,7 +36,7 @@ class Poller: private NonCopyable public: struct PolledObject { - EventObject *object = 0; + EventObject *object = nullptr; PollEvent events = P_NONE; PolledObject(EventObject *o, PollEvent e): object(o), events(e) { } @@ -46,7 +46,7 @@ private: struct Private; std::vector objects; - Private *priv = 0; + Private *priv = nullptr; bool events_changed = false; bool objs_changed = false; std::vector poll_result; diff --git a/source/io/windows/eventreader.cpp b/source/io/windows/eventreader.cpp index 8c41020..4a0640f 100644 --- a/source/io/windows/eventreader.cpp +++ b/source/io/windows/eventreader.cpp @@ -14,9 +14,9 @@ struct EventReader::Private OVERLAPPED overlapped; Handle event; size_t buf_size = 0; - char *buffer = 0; + char *buffer = nullptr; size_t buf_avail = 0; - char *buf_next = 0; + char *buf_next = nullptr; bool pending = false; bool eof = false; }; @@ -27,7 +27,7 @@ EventReader::EventReader(Handle &h, unsigned size): priv(new Private) { memset(&priv->overlapped, 0, sizeof(OVERLAPPED)); - *priv->event = CreateEvent(0, true, false, 0); + *priv->event = CreateEvent(nullptr, true, false, nullptr); priv->overlapped.hEvent = *priv->event; priv->buf_size = size; priv->buffer = new char[priv->buf_size]; diff --git a/source/io/windows/file.cpp b/source/io/windows/file.cpp index 3cbdc4a..90c5bb5 100644 --- a/source/io/windows/file.cpp +++ b/source/io/windows/file.cpp @@ -35,10 +35,10 @@ void File::platform_init(const string &fn, CreateMode cm) SECURITY_ATTRIBUTES sec_attr; sec_attr.nLength = sizeof(SECURITY_ATTRIBUTES); - sec_attr.lpSecurityDescriptor = 0; + sec_attr.lpSecurityDescriptor = nullptr; sec_attr.bInheritHandle = !!(mode&M_INHERIT); - *handle = CreateFile(fn.c_str(), flags, share_flags, 0, create_flags, FILE_ATTRIBUTE_NORMAL, &sec_attr); + *handle = CreateFile(fn.c_str(), flags, share_flags, nullptr, create_flags, FILE_ATTRIBUTE_NORMAL, &sec_attr); if(!handle) { int err = GetLastError(); diff --git a/source/io/windows/handle.cpp b/source/io/windows/handle.cpp index 1cdf8ce..6d1219a 100644 --- a/source/io/windows/handle.cpp +++ b/source/io/windows/handle.cpp @@ -23,7 +23,7 @@ size_t sys_read(Handle &handle, char *buf, size_t size) throw invalid_argument("read"); DWORD ret; - if(ReadFile(*handle, buf, size, &ret, 0)==0) + if(ReadFile(*handle, buf, size, &ret, nullptr)==0) throw system_error("ReadFile"); return ret; @@ -35,7 +35,7 @@ size_t sys_write(Handle &handle, const char *buf, size_t size) throw invalid_argument("write"); DWORD ret; - if(WriteFile(*handle, buf, size, &ret, 0)==0) + if(WriteFile(*handle, buf, size, &ret, nullptr)==0) throw system_error("WriteFile"); return ret; diff --git a/source/io/windows/pipe.cpp b/source/io/windows/pipe.cpp index 02d7f33..70d256c 100644 --- a/source/io/windows/pipe.cpp +++ b/source/io/windows/pipe.cpp @@ -11,11 +11,11 @@ namespace IO { void Pipe::platform_init() { string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this); - *read_handle = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0); + *read_handle = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, nullptr); if(!read_handle) throw system_error("CreateNamedPipe"); - *write_handle = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); + *write_handle = CreateFile(name.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr); if(!write_handle) { unsigned err = GetLastError(); diff --git a/source/io/windows/serial.cpp b/source/io/windows/serial.cpp index 84a3175..bd086dd 100644 --- a/source/io/windows/serial.cpp +++ b/source/io/windows/serial.cpp @@ -13,7 +13,7 @@ void Serial::platform_init(const string &port) { string name = "\\\\.\\"+port; - *handle = CreateFile(name.c_str(), GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, 0); + *handle = CreateFile(name.c_str(), GENERIC_READ|GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, nullptr); if(!handle) throw system_error(format("CreateFile(%s)", port)); mode = M_READ|M_WRITE; diff --git a/source/io/zlibcompressed.cpp b/source/io/zlibcompressed.cpp index 6c06cf3..fba71eb 100644 --- a/source/io/zlibcompressed.cpp +++ b/source/io/zlibcompressed.cpp @@ -30,9 +30,9 @@ struct ZlibCompressed::Private ZlibCompressed::Private::Private() { #ifdef WITH_ZLIB - stream.zalloc = 0; - stream.zfree = 0; - stream.opaque = 0; + stream.zalloc = nullptr; + stream.zfree = nullptr; + stream.opaque = nullptr; #endif } diff --git a/source/io/zlibcompressed.h b/source/io/zlibcompressed.h index da7313b..7a79734 100644 --- a/source/io/zlibcompressed.h +++ b/source/io/zlibcompressed.h @@ -35,10 +35,10 @@ private: Base &below; std::size_t buffer_size = 1024; - unsigned char *in_buffer = 0; - unsigned char *out_buffer = 0; + unsigned char *in_buffer = nullptr; + unsigned char *out_buffer = nullptr; bool stream_end = false; - Private *priv = 0; + Private *priv = nullptr; public: /** Creates a zlib de/compression object. The underlying object must be diff --git a/source/stringcodec/iso2022jp.h b/source/stringcodec/iso2022jp.h index dd85014..a304c56 100644 --- a/source/stringcodec/iso2022jp.h +++ b/source/stringcodec/iso2022jp.h @@ -36,7 +36,7 @@ public: { private: Mode mode = ASCII; - Codec::Decoder *dec = 0; + Codec::Decoder *dec = nullptr; public: Decoder(ErrorMode = DEFAULT); diff --git a/source/time/timer.cpp b/source/time/timer.cpp index d35d127..04c3074 100644 --- a/source/time/timer.cpp +++ b/source/time/timer.cpp @@ -71,7 +71,7 @@ void Timer::do_tick(const TimeDelta &timeout) if(timeout>=zero) deadline = now()+timeout; - Slot *next = 0; + Slot *next = nullptr; { MutexLock l(mutex); while(1) diff --git a/source/time/timer.h b/source/time/timer.h index 91acda9..3325731 100644 --- a/source/time/timer.h +++ b/source/time/timer.h @@ -41,7 +41,7 @@ public: private: struct SlotProxy { - Slot *slot = 0; + Slot *slot = nullptr; SlotProxy(Slot *); bool operator<(const SlotProxy &) const; diff --git a/source/time/unix/utils.cpp b/source/time/unix/utils.cpp index 029c75b..f25f61c 100644 --- a/source/time/unix/utils.cpp +++ b/source/time/unix/utils.cpp @@ -13,7 +13,7 @@ namespace Time { TimeStamp now() { timeval tv; - gettimeofday(&tv, 0); + gettimeofday(&tv, nullptr); return TimeStamp(timeval_to_rawtime(tv)); } @@ -27,7 +27,7 @@ TimeDelta get_cpu_time() void sleep(const TimeDelta &d) { timespec ts = rawtime_to_timespec(d.raw()); - while(nanosleep(&ts, 0)==-1) + while(nanosleep(&ts, nullptr)==-1) if(errno!=EINTR) throw system_error("nanosleep"); }