From 8cedfb81967da428ed81bbca2eda906496c3b106 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Sat, 2 Feb 2019 16:27:12 +0800 Subject: [PATCH] src: refactor to nullptr in cpp code Signed-off-by: gengjiawen PR-URL: https://github.com/nodejs/node/pull/25888 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Refael Ackermann --- src/cares_wrap.cc | 7 ++++--- src/debug_utils.cc | 3 ++- src/node.h | 6 ++++-- src/node_crypto.cc | 10 ++++++---- src/util-inl.h | 2 +- src/util.cc | 2 +- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 57c02fb32653e5..de05123c22cf4a 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -395,7 +395,7 @@ void safe_free_hostent(struct hostent* host) { free(host->h_addr_list[idx++]); } free(host->h_addr_list); - host->h_addr_list = 0; + host->h_addr_list = nullptr; } if (host->h_aliases != nullptr) { @@ -404,7 +404,7 @@ void safe_free_hostent(struct hostent* host) { free(host->h_aliases[idx++]); } free(host->h_aliases); - host->h_aliases = 0; + host->h_aliases = nullptr; } if (host->h_name != nullptr) { @@ -1914,7 +1914,8 @@ void AfterGetNameInfo(uv_getnameinfo_t* req, req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); } -using ParseIPResult = decltype(static_cast(0)->addr); +using ParseIPResult = + decltype(static_cast(nullptr)->addr); int ParseIP(const char* ip, ParseIPResult* result = nullptr) { ParseIPResult tmp; diff --git a/src/debug_utils.cc b/src/debug_utils.cc index 434c9853c02a2e..fadcaa50619f63 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -66,7 +66,8 @@ class PosixSymbolDebuggingContext final : public NativeSymbolDebuggingContext { return ret; if (info.dli_sname != nullptr) { - if (char* demangled = abi::__cxa_demangle(info.dli_sname, 0, 0, 0)) { + if (char* demangled = + abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, nullptr)) { ret.name = demangled; free(demangled); } else { diff --git a/src/node.h b/src/node.h index c260d172c01ebf..0bdd37421b150e 100644 --- a/src/node.h +++ b/src/node.h @@ -562,13 +562,15 @@ extern "C" NODE_EXTERN void node_module_register(void* mod); /* Called after the event loop exits but before the VM is disposed. * Callbacks are run in reverse order of registration, i.e. newest first. */ -NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = 0); +NODE_EXTERN void AtExit(void (*cb)(void* arg), void* arg = nullptr); /* Registers a callback with the passed-in Environment instance. The callback * is called after the event loop exits, but before the VM is disposed. * Callbacks are run in reverse order of registration, i.e. newest first. */ -NODE_EXTERN void AtExit(Environment* env, void (*cb)(void* arg), void* arg = 0); +NODE_EXTERN void AtExit(Environment* env, + void (*cb)(void* arg), + void* arg = nullptr); typedef void (*promise_hook_func) (v8::PromiseHookType type, v8::Local promise, diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 260189b5acb431..6808c17fdd9d7a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4818,7 +4818,7 @@ void DiffieHellman::Initialize(Environment* env, Local target) { bool DiffieHellman::Init(int primeLength, int g) { dh_.reset(DH_new()); - if (!DH_generate_parameters_ex(dh_.get(), primeLength, g, 0)) + if (!DH_generate_parameters_ex(dh_.get(), primeLength, g, nullptr)) return false; return VerifyContext(); } @@ -4841,8 +4841,10 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) { bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) { dh_.reset(DH_new()); - BIGNUM* bn_p = BN_bin2bn(reinterpret_cast(p), p_len, 0); - BIGNUM* bn_g = BN_bin2bn(reinterpret_cast(g), g_len, 0); + BIGNUM* bn_p = + BN_bin2bn(reinterpret_cast(p), p_len, nullptr); + BIGNUM* bn_g = + BN_bin2bn(reinterpret_cast(g), g_len, nullptr); if (!DH_set0_pqg(dh_.get(), bn_p, nullptr, bn_g)) { BN_free(bn_p); BN_free(bn_g); @@ -5010,7 +5012,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo& args) { BignumPointer key(BN_bin2bn( reinterpret_cast(Buffer::Data(args[0])), Buffer::Length(args[0]), - 0)); + nullptr)); MallocedBuffer data(DH_size(diffieHellman->dh_.get())); diff --git a/src/util-inl.h b/src/util-inl.h index 182c50268d3e0a..9f57b635db3357 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -143,7 +143,7 @@ typename ListHead::Iterator ListHead::end() const { template constexpr uintptr_t OffsetOf(Inner Outer::*field) { - return reinterpret_cast(&(static_cast(0)->*field)); + return reinterpret_cast(&(static_cast(nullptr)->*field)); } template diff --git a/src/util.cc b/src/util.cc index 9f32814a8599ec..81070c239d8ad4 100644 --- a/src/util.cc +++ b/src/util.cc @@ -48,7 +48,7 @@ static void MakeUtf8String(Isolate* isolate, const int flags = String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8; const int length = - string->WriteUtf8(isolate, target->out(), storage, 0, flags); + string->WriteUtf8(isolate, target->out(), storage, nullptr, flags); target->SetLengthAndZeroTerminate(length); }