src: refactor to nullptr in cpp code

Signed-off-by: gengjiawen <technicalcute@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/25888
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
gengjiawen 2019-02-02 16:27:12 +08:00 committed by Daniel Bevenius
parent b8d9d4ac68
commit abba1020f4
6 changed files with 18 additions and 12 deletions

View File

@ -395,7 +395,7 @@ void safe_free_hostent(struct hostent* host) {
free(host->h_addr_list[idx++]); free(host->h_addr_list[idx++]);
} }
free(host->h_addr_list); free(host->h_addr_list);
host->h_addr_list = 0; host->h_addr_list = nullptr;
} }
if (host->h_aliases != 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[idx++]);
} }
free(host->h_aliases); free(host->h_aliases);
host->h_aliases = 0; host->h_aliases = nullptr;
} }
if (host->h_name != 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); req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
} }
using ParseIPResult = decltype(static_cast<ares_addr_port_node*>(0)->addr); using ParseIPResult =
decltype(static_cast<ares_addr_port_node*>(nullptr)->addr);
int ParseIP(const char* ip, ParseIPResult* result = nullptr) { int ParseIP(const char* ip, ParseIPResult* result = nullptr) {
ParseIPResult tmp; ParseIPResult tmp;

View File

@ -66,7 +66,8 @@ class PosixSymbolDebuggingContext final : public NativeSymbolDebuggingContext {
return ret; return ret;
if (info.dli_sname != nullptr) { 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; ret.name = demangled;
free(demangled); free(demangled);
} else { } else {

View File

@ -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. /* Called after the event loop exits but before the VM is disposed.
* Callbacks are run in reverse order of registration, i.e. newest first. * 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 /* Registers a callback with the passed-in Environment instance. The callback
* is called after the event loop exits, but before the VM is disposed. * 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. * 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, typedef void (*promise_hook_func) (v8::PromiseHookType type,
v8::Local<v8::Promise> promise, v8::Local<v8::Promise> promise,

View File

@ -4817,7 +4817,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) {
bool DiffieHellman::Init(int primeLength, int g) { bool DiffieHellman::Init(int primeLength, int g) {
dh_.reset(DH_new()); 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 false;
return VerifyContext(); return VerifyContext();
} }
@ -4840,8 +4840,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) { bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
dh_.reset(DH_new()); dh_.reset(DH_new());
BIGNUM* bn_p = BN_bin2bn(reinterpret_cast<const unsigned char*>(p), p_len, 0); BIGNUM* bn_p =
BIGNUM* bn_g = BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, 0); BN_bin2bn(reinterpret_cast<const unsigned char*>(p), p_len, nullptr);
BIGNUM* bn_g =
BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, nullptr);
if (!DH_set0_pqg(dh_.get(), bn_p, nullptr, bn_g)) { if (!DH_set0_pqg(dh_.get(), bn_p, nullptr, bn_g)) {
BN_free(bn_p); BN_free(bn_p);
BN_free(bn_g); BN_free(bn_g);
@ -5009,7 +5011,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) {
BignumPointer key(BN_bin2bn( BignumPointer key(BN_bin2bn(
reinterpret_cast<unsigned char*>(Buffer::Data(args[0])), reinterpret_cast<unsigned char*>(Buffer::Data(args[0])),
Buffer::Length(args[0]), Buffer::Length(args[0]),
0)); nullptr));
MallocedBuffer<char> data(DH_size(diffieHellman->dh_.get())); MallocedBuffer<char> data(DH_size(diffieHellman->dh_.get()));

View File

@ -143,7 +143,7 @@ typename ListHead<T, M>::Iterator ListHead<T, M>::end() const {
template <typename Inner, typename Outer> template <typename Inner, typename Outer>
constexpr uintptr_t OffsetOf(Inner Outer::*field) { constexpr uintptr_t OffsetOf(Inner Outer::*field) {
return reinterpret_cast<uintptr_t>(&(static_cast<Outer*>(0)->*field)); return reinterpret_cast<uintptr_t>(&(static_cast<Outer*>(nullptr)->*field));
} }
template <typename Inner, typename Outer> template <typename Inner, typename Outer>

View File

@ -48,7 +48,7 @@ static void MakeUtf8String(Isolate* isolate,
const int flags = const int flags =
String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8; String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8;
const int length = const int length =
string->WriteUtf8(isolate, target->out(), storage, 0, flags); string->WriteUtf8(isolate, target->out(), storage, nullptr, flags);
target->SetLengthAndZeroTerminate(length); target->SetLengthAndZeroTerminate(length);
} }