diff options
48 files changed, 655 insertions, 647 deletions
diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index 4cbf8f493b..6fad7eac36 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -100,7 +100,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback( v8::Local<v8::Function> enter = domain->Get(env()->enter_string()).As<v8::Function>(); if (enter->IsFunction()) { - enter->Call(domain, 0, NULL); + enter->Call(domain, 0, nullptr); if (try_catch.HasCaught()) return Undefined(env()->isolate()); } @@ -116,7 +116,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback( v8::Local<v8::Function> exit = domain->Get(env()->exit_string()).As<v8::Function>(); if (exit->IsFunction()) { - exit->Call(domain, 0, NULL); + exit->Call(domain, 0, nullptr); if (try_catch.HasCaught()) return Undefined(env()->isolate()); } @@ -147,7 +147,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback( tick_info->set_in_tick(true); - env()->tick_callback_function()->Call(process, 0, NULL); + env()->tick_callback_function()->Call(process, 0, nullptr); tick_info->set_in_tick(false); @@ -214,7 +214,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback( tick_info->set_in_tick(true); - env()->tick_callback_function()->Call(process, 0, NULL); + env()->tick_callback_function()->Call(process, 0, nullptr); tick_info->set_in_tick(false); diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 88645c408c..987bbd7e88 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -121,9 +121,9 @@ static void ares_poll_close_cb(uv_handle_t* watcher) { static ares_task_t* ares_task_create(Environment* env, ares_socket_t sock) { ares_task_t* task = static_cast<ares_task_t*>(malloc(sizeof(*task))); - if (task == NULL) { + if (task == nullptr) { /* Out of memory. */ - return NULL; + return nullptr; } task->env = env; @@ -132,7 +132,7 @@ static ares_task_t* ares_task_create(Environment* env, ares_socket_t sock) { if (uv_poll_init_socket(env->event_loop(), &task->poll_watcher, sock) < 0) { /* This should never happen. */ free(task); - return NULL; + return nullptr; } return task; @@ -163,7 +163,7 @@ static void ares_sockstate_cb(void* data, } task = ares_task_create(env, sock); - if (task == NULL) { + if (task == nullptr) { /* This should never happen unless we're out of memory or something */ /* is seriously wrong. The socket won't be polled, but the the query */ /* will eventually time out. */ @@ -202,7 +202,7 @@ static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) { Local<Array> addresses = Array::New(env->isolate()); char ip[INET6_ADDRSTRLEN]; - for (uint32_t i = 0; host->h_addr_list[i] != NULL; ++i) { + for (uint32_t i = 0; host->h_addr_list[i] != nullptr; ++i) { uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip)); Local<String> address = OneByteString(env->isolate(), ip); addresses->Set(i, address); @@ -216,7 +216,7 @@ static Local<Array> HostentToNames(Environment* env, struct hostent* host) { EscapableHandleScope scope(env->isolate()); Local<Array> names = Array::New(env->isolate()); - for (uint32_t i = 0; host->h_aliases[i] != NULL; ++i) { + for (uint32_t i = 0; host->h_aliases[i] != nullptr; ++i) { Local<String> address = OneByteString(env->isolate(), host->h_aliases[i]); names->Set(i, address); } @@ -375,7 +375,7 @@ class QueryAWrap: public QueryWrap { struct hostent* host; - int status = ares_parse_a_reply(buf, len, &host, NULL, NULL); + int status = ares_parse_a_reply(buf, len, &host, nullptr, nullptr); if (status != ARES_SUCCESS) { ParseError(status); return; @@ -412,7 +412,7 @@ class QueryAaaaWrap: public QueryWrap { struct hostent* host; - int status = ares_parse_aaaa_reply(buf, len, &host, NULL, NULL); + int status = ares_parse_aaaa_reply(buf, len, &host, nullptr, nullptr); if (status != ARES_SUCCESS) { ParseError(status); return; @@ -448,7 +448,7 @@ class QueryCnameWrap: public QueryWrap { Context::Scope context_scope(env()->context()); struct hostent* host; - int status = ares_parse_a_reply(buf, len, &host, NULL, NULL); + int status = ares_parse_a_reply(buf, len, &host, nullptr, nullptr); if (status != ARES_SUCCESS) { ParseError(status); return; @@ -498,7 +498,7 @@ class QueryMxWrap: public QueryWrap { Local<String> priority_symbol = env()->priority_string(); ares_mx_reply* current = mx_start; - for (uint32_t i = 0; current != NULL; ++i, current = current->next) { + for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { Local<Object> mx_record = Object::New(env()->isolate()); mx_record->Set(exchange_symbol, OneByteString(env()->isolate(), current->host)); @@ -583,7 +583,7 @@ class QueryTxtWrap: public QueryWrap { ares_txt_reply* current = txt_out; uint32_t i = 0; - for (uint32_t j = 0; current != NULL; current = current->next) { + for (uint32_t j = 0; current != nullptr; current = current->next) { Local<String> txt = OneByteString(env()->isolate(), current->txt); // New record found - write out the current chunk if (current->record_start) { @@ -639,7 +639,7 @@ class QuerySrvWrap: public QueryWrap { Local<String> weight_symbol = env()->weight_string(); ares_srv_reply* current = srv_start; - for (uint32_t i = 0; current != NULL; ++i, current = current->next) { + for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { Local<Object> srv_record = Object::New(env()->isolate()); srv_record->Set(name_symbol, OneByteString(env()->isolate(), current->host)); @@ -696,7 +696,7 @@ class QueryNaptrWrap: public QueryWrap { Local<String> preference_symbol = env()->preference_string(); ares_naptr_reply* current = naptr_start; - for (uint32_t i = 0; current != NULL; ++i, current = current->next) { + for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { Local<Object> naptr_record = Object::New(env()->isolate()); naptr_record->Set(flags_symbol, OneByteString(env()->isolate(), current->flags)); @@ -1044,7 +1044,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) { &req_wrap->req_, AfterGetAddrInfo, *hostname, - NULL, + nullptr, &hints); req_wrap->Dispatched(); if (err) @@ -1098,7 +1098,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) { ares_addr_node* cur = servers; - for (uint32_t i = 0; cur != NULL; ++i, cur = cur->next) { + for (uint32_t i = 0; cur != nullptr; ++i, cur = cur->next) { char ip[INET6_ADDRSTRLEN]; const void* caddr = static_cast<const void*>(&cur->addr); @@ -1125,12 +1125,12 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) { uint32_t len = arr->Length(); if (len == 0) { - int rv = ares_set_servers(env->cares_channel(), NULL); + int rv = ares_set_servers(env->cares_channel(), nullptr); return args.GetReturnValue().Set(rv); } ares_addr_node* servers = new ares_addr_node[len]; - ares_addr_node* last = NULL; + ares_addr_node* last = nullptr; int err; @@ -1164,9 +1164,9 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) { if (err) break; - cur->next = NULL; + cur->next = nullptr; - if (last != NULL) + if (last != nullptr) last->next = cur; last = cur; @@ -1230,7 +1230,7 @@ static void Initialize(Handle<Object> target, env->RegisterHandleCleanup( reinterpret_cast<uv_handle_t*>(env->cares_timer_handle()), CaresTimerClose, - NULL); + nullptr); env->SetMethod(target, "queryA", Query<QueryAWrap>); env->SetMethod(target, "queryAaaa", Query<QueryAaaaWrap>); diff --git a/src/env-inl.h b/src/env-inl.h index c0465843d4..b770538e63 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -76,7 +76,7 @@ inline Environment::IsolateData* Environment::IsolateData::Get( inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( v8::Isolate* isolate, uv_loop_t* loop) { IsolateData* isolate_data = Get(isolate); - if (isolate_data == NULL) { + if (isolate_data == nullptr) { isolate_data = new IsolateData(isolate, loop); isolate->SetData(kIsolateSlot, isolate_data); } @@ -86,7 +86,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate( inline void Environment::IsolateData::Put() { if (--ref_count_ == 0) { - isolate()->SetData(kIsolateSlot, NULL); + isolate()->SetData(kIsolateSlot, nullptr); delete this; } } @@ -246,7 +246,8 @@ inline Environment::Environment(v8::Local<v8::Context> context, inline Environment::~Environment() { v8::HandleScope handle_scope(isolate()); - context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL); + context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, + nullptr); #define V(PropertyName, TypeName) PropertyName ## _.Reset(); ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) #undef V @@ -442,13 +442,13 @@ class Environment { inline void ThrowTypeError(const char* errmsg); inline void ThrowRangeError(const char* errmsg); inline void ThrowErrnoException(int errorno, - const char* syscall = NULL, - const char* message = NULL, - const char* path = NULL); + const char* syscall = nullptr, + const char* message = nullptr, + const char* path = nullptr); inline void ThrowUVException(int errorno, - const char* syscall = NULL, - const char* message = NULL, - const char* path = NULL); + const char* syscall = nullptr, + const char* message = nullptr, + const char* path = nullptr); // Convenience methods for contextify inline static void ThrowError(v8::Isolate* isolate, const char* errmsg); diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 06e5ef44d9..8f381b40a7 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -175,7 +175,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, Null(env->isolate()) }; - if (filename != NULL) { + if (filename != nullptr) { argv[2] = OneByteString(env->isolate(), filename); } @@ -186,7 +186,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) { FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder()); - if (wrap == NULL || wrap->initialized_ == false) + if (wrap == nullptr || wrap->initialized_ == false) return; wrap->initialized_ = false; diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index ecca915c43..595ea7d3a5 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -43,7 +43,7 @@ using v8::Value; void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) { HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); - if (wrap != NULL && wrap->handle__ != NULL) { + if (wrap != nullptr && wrap->handle__ != nullptr) { uv_ref(wrap->handle__); wrap->flags_ &= ~kUnref; } @@ -53,7 +53,7 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) { void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) { HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); - if (wrap != NULL && wrap->handle__ != NULL) { + if (wrap != nullptr && wrap->handle__ != nullptr) { uv_unref(wrap->handle__); wrap->flags_ |= kUnref; } @@ -66,12 +66,12 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) { HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); // guard against uninitialized handle or double close - if (wrap == NULL || wrap->handle__ == NULL) + if (wrap == nullptr || wrap->handle__ == nullptr) return; CHECK_EQ(false, wrap->persistent().IsEmpty()); uv_close(wrap->handle__, OnClose); - wrap->handle__ = NULL; + wrap->handle__ = nullptr; if (args[0]->IsFunction()) { wrap->object()->Set(env->close_string(), args[0]); @@ -109,17 +109,17 @@ void HandleWrap::OnClose(uv_handle_t* handle) { CHECK_EQ(wrap->persistent().IsEmpty(), false); // But the handle pointer should be gone. - CHECK_EQ(wrap->handle__, NULL); + CHECK_EQ(wrap->handle__, nullptr); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); Local<Object> object = wrap->object(); if (wrap->flags_ & kCloseCallback) { - wrap->MakeCallback(env->close_string(), 0, NULL); + wrap->MakeCallback(env->close_string(), 0, nullptr); } - object->SetAlignedPointerInInternalField(0, NULL); + object->SetAlignedPointerInInternalField(0, nullptr); wrap->persistent().Reset(); delete wrap; } diff --git a/src/node.cc b/src/node.cc index afb5747ade..6ae55f0db9 100644 --- a/src/node.cc +++ b/src/node.cc @@ -126,7 +126,7 @@ static bool print_eval = false; static bool force_repl = false; static bool trace_deprecation = false; static bool throw_deprecation = false; -static const char* eval_string = NULL; +static const char* eval_string = nullptr; static bool use_debug_agent = false; static bool debug_wait_connect = false; static int debug_port = 5858; @@ -137,7 +137,7 @@ static node_module* modlist_addon; #if defined(NODE_HAVE_I18N_SUPPORT) // Path to ICU data (for i18n / Intl) -static const char* icu_data_dir = NULL; +static const char* icu_data_dir = nullptr; #endif // used by C++ modules as well @@ -148,7 +148,7 @@ static double prog_start_time; static bool debugger_running; static uv_async_t dispatch_debug_messages_async; -static Isolate* node_isolate = NULL; +static Isolate* node_isolate = nullptr; int WRITE_UTF8_FLAGS = v8::String::HINT_MANY_WRITES_EXPECTED | v8::String::NO_NULL_TERMINATION; @@ -174,7 +174,7 @@ ArrayBufferAllocator ArrayBufferAllocator::the_singleton; void* ArrayBufferAllocator::Allocate(size_t length) { if (length > kMaxLength) - return NULL; + return nullptr; char* data = new char[length]; memset(data, 0, length); return data; @@ -183,7 +183,7 @@ void* ArrayBufferAllocator::Allocate(size_t length) { void* ArrayBufferAllocator::AllocateUninitialized(size_t length) { if (length > kMaxLength) - return NULL; + return nullptr; return new char[length]; } @@ -203,7 +203,7 @@ static void CheckImmediate(uv_check_t* handle) { static void IdleImmediateDummy(uv_idle_t* handle) { // Do nothing. Only for maintaining event loop. - // TODO(bnoordhuis) Maybe make libuv accept NULL idle callbacks. + // TODO(bnoordhuis) Maybe make libuv accept nullptr idle callbacks. } @@ -735,7 +735,7 @@ Local<Value> ErrnoException(Isolate* isolate, Local<Value> e; Local<String> estring = OneByteString(env->isolate(), errno_string(errorno)); - if (msg == NULL || msg[0] == '\0') { + if (msg == nullptr || msg[0] == '\0') { msg = strerror(errorno); } Local<String> message = OneByteString(env->isolate(), msg); @@ -760,11 +760,11 @@ Local<Value> ErrnoException(Isolate* isolate, obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno)); obj->Set(env->code_string(), estring); - if (path != NULL) { + if (path != nullptr) { obj->Set(env->path_string(), String::NewFromUtf8(env->isolate(), path)); } - if (syscall != NULL) { + if (syscall != nullptr) { obj->Set(env->syscall_string(), OneByteString(env->isolate(), syscall)); } @@ -823,11 +823,11 @@ Local<Value> UVException(Isolate* isolate, obj->Set(env->errno_string(), Integer::New(env->isolate(), errorno)); obj->Set(env->code_string(), estring); - if (path != NULL) { + if (path != nullptr) { obj->Set(env->path_string(), path_str); } - if (syscall != NULL) { + if (syscall != nullptr) { obj->Set(env->syscall_string(), OneByteString(env->isolate(), syscall)); } @@ -839,7 +839,7 @@ Local<Value> UVException(Isolate* isolate, inline const char* secure_getenv(const char* key) { #ifndef _WIN32 if (getuid() != geteuid() || getgid() != getegid()) - return NULL; + return nullptr; #endif return getenv(key); } @@ -849,11 +849,11 @@ inline const char* secure_getenv(const char* key) { // Does about the same as strerror(), // but supports all windows error messages static const char *winapi_strerror(const int errorno, bool* must_free) { - char *errmsg = NULL; + char *errmsg = nullptr; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errmsg, 0, NULL); + FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorno, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errmsg, 0, nullptr); if (errmsg) { *must_free = true; @@ -901,11 +901,11 @@ Local<Value> WinapiErrnoException(Isolate* isolate, Local<Object> obj = e->ToObject(); obj->Set(env->errno_string(), Integer::New(isolate, errorno)); - if (path != NULL) { + if (path != nullptr) { obj->Set(env->path_string(), String::NewFromUtf8(isolate, path)); } - if (syscall != NULL) { + if (syscall != nullptr) { obj->Set(env->syscall_string(), OneByteString(isolate, syscall)); } @@ -1054,7 +1054,7 @@ Handle<Value> MakeDomainCallback(Environment* env, Local<Function> enter = domain->Get(env->enter_string()).As<Function>(); if (enter->IsFunction()) { - enter->Call(domain, 0, NULL); + enter->Call(domain, 0, nullptr); if (try_catch.HasCaught()) return Undefined(env->isolate()); } @@ -1070,7 +1070,7 @@ Handle<Value> MakeDomainCallback(Environment* env, if (has_domain) { Local<Function> exit = domain->Get(env->exit_string()).As<Function>(); if (exit->IsFunction()) { - exit->Call(domain, 0, NULL); + exit->Call(domain, 0, nullptr); if (try_catch.HasCaught()) return Undefined(env->isolate()); } @@ -1105,7 +1105,7 @@ Handle<Value> MakeDomainCallback(Environment* env, tick_info->set_in_tick(true); - env->tick_callback_function()->Call(process, 0, NULL); + env->tick_callback_function()->Call(process, 0, nullptr); tick_info->set_in_tick(false); @@ -1174,7 +1174,7 @@ Handle<Value> MakeCallback(Environment* env, tick_info->set_in_tick(true); // process nextTicks after call - env->tick_callback_function()->Call(process, 0, NULL); + env->tick_callback_function()->Call(process, 0, nullptr); tick_info->set_in_tick(false); @@ -1359,7 +1359,7 @@ ssize_t DecodeWrite(Isolate* isolate, size_t buflen, Handle<Value> val, enum encoding encoding) { - return StringBytes::Write(isolate, buf, buflen, val, encoding, NULL); + return StringBytes::Write(isolate, buf, buflen, val, encoding, nullptr); } void AppendExceptionLine(Environment* env, @@ -1557,7 +1557,7 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Local<Array> ary = Array::New(args.GetIsolate()); - QUEUE* q = NULL; + QUEUE* q = nullptr; int i = 0; QUEUE_FOREACH(q, env->req_wrap_queue()) { @@ -1577,7 +1577,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Local<Array> ary = Array::New(env->isolate()); - QUEUE* q = NULL; + QUEUE* q = nullptr; int i = 0; Local<String> owner_sym = env->owner_string(); @@ -1687,9 +1687,9 @@ static uid_t uid_by_name(const char* name) { char buf[8192]; errno = 0; - pp = NULL; + pp = nullptr; - if (getpwnam_r(name, &pwd, buf, sizeof(buf), &pp) == 0 && pp != NULL) { + if (getpwnam_r(name, &pwd, buf, sizeof(buf), &pp) == 0 && pp != nullptr) { return pp->pw_uid; } @@ -1704,9 +1704,10 @@ static char* name_by_uid(uid_t uid) { int rc; errno = 0; - pp = NULL; + pp = nullptr; - if ((rc = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pp)) == 0 && pp != NULL) { + if ((rc = getpwuid_r(uid, &pwd, buf, sizeof(buf), &pp)) == 0 && + pp != nullptr) { return strdup(pp->pw_name); } @@ -1714,7 +1715,7 @@ static char* name_by_uid(uid_t uid) { errno = ENOENT; } - return NULL; + return nullptr; } @@ -1724,9 +1725,9 @@ static gid_t gid_by_name(const char* name) { char buf[8192]; errno = 0; - pp = NULL; + pp = nullptr; - if (getgrnam_r(name, &pwd, buf, sizeof(buf), &pp) == 0 && pp != NULL) { + if (getgrnam_r(name, &pwd, buf, sizeof(buf), &pp) == 0 && pp != nullptr) { return pp->gr_gid; } @@ -1742,9 +1743,10 @@ static const char* name_by_gid(gid_t gid) { int rc; errno = 0; - pp = NULL; + pp = nullptr; - if ((rc = getgrgid_r(gid, &pwd, buf, sizeof(buf), &pp)) == 0 && pp != NULL) { + if ((rc = getgrgid_r(gid, &pwd, buf, sizeof(buf), &pp)) == 0 && + pp != nullptr) { return strdup(pp->gr_name); } @@ -1752,7 +1754,7 @@ static const char* name_by_gid(gid_t gid) { errno = ENOENT; } - return NULL; + return nullptr; } #endif @@ -1830,7 +1832,7 @@ static void SetUid(const FunctionCallbackInfo<Value>& args) { static void GetGroups(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - int ngroups = getgroups(0, NULL); + int ngroups = getgroups(0, nullptr); if (ngroups == -1) { return env->ThrowErrnoException(errno, "getgroups"); @@ -1920,7 +1922,7 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) { must_free = false; } - if (user == NULL) { + if (user == nullptr) { return env->ThrowError("initgroups user not found"); } @@ -2040,7 +2042,7 @@ extern "C" void node_module_register(void* m) { mp->nm_link = modlist_builtin; modlist_builtin = mp; } else { - CHECK_EQ(modpending, NULL); + CHECK_EQ(modpending, nullptr); modpending = mp; } } @@ -2048,12 +2050,12 @@ extern "C" void node_module_register(void* m) { struct node_module* get_builtin_module(const char* name) { struct node_module* mp; - for (mp = modlist_builtin; mp != NULL; mp = mp->nm_link) { + for (mp = modlist_builtin; mp != nullptr; mp = mp->nm_link) { if (strcmp(mp->nm_modname, name) == 0) break; } - CHECK(mp == NULL || (mp->nm_flags & NM_F_BUILTIN) != 0); + CHECK(mp == nullptr || (mp->nm_flags & NM_F_BUILTIN) != 0); return (mp); } @@ -2097,9 +2099,9 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { * module per object is supported. */ mp = modpending; - modpending = NULL; + modpending = nullptr; - if (mp == NULL) { + if (mp == nullptr) { env->ThrowError("Module did not self-register."); return; } @@ -2121,9 +2123,9 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) { mp->nm_link = modlist_addon; modlist_addon = mp; - if (mp->nm_context_register_func != NULL) { + if (mp->nm_context_register_func != nullptr) { mp->nm_context_register_func(exports, module, env->context(), mp->nm_priv); - } else if (mp->nm_register_func != NULL) { + } else if (mp->nm_register_func != nullptr) { mp->nm_register_func(exports, module, mp->nm_priv); } else { env->ThrowError("Module has no declared entry point."); @@ -2232,11 +2234,11 @@ static void Binding(const FunctionCallbackInfo<Value>& args) { modules->Set(l, OneByteString(env->isolate(), buf)); node_module* mod = get_builtin_module(*module_v); - if (mod != NULL) { + if (mod != nullptr) { exports = Object::New(env->isolate()); // Internal bindings don't have a "module" object, only exports. - CHECK_EQ(mod->nm_register_func, NULL); - CHECK_NE(mod->nm_context_register_func, NULL); + CHECK_EQ(mod->nm_register_func, nullptr); + CHECK_NE(mod->nm_context_register_func, nullptr); Local<Value> unused = Undefined(env->isolate()); mod->nm_context_register_func(exports, unused, env->context(), mod->nm_priv); @@ -2350,7 +2352,7 @@ static void EnvQuery(Local<String> property, #else // _WIN32 String::Value key(property); WCHAR* key_ptr = reinterpret_cast<WCHAR*>(*key); - if (GetEnvironmentVariableW(key_ptr, NULL, 0) > 0 || + if (GetEnvironmentVariableW(key_ptr, nullptr, 0) > 0 || GetLastError() == ERROR_SUCCESS) { rc = 0; if (key_ptr[0] == L'=') { @@ -2373,16 +2375,16 @@ static void EnvDeleter(Local<String> property, bool rc = true; #ifdef __POSIX__ node::Utf8Value key(property); - rc = getenv(*key) != NULL; + rc = getenv(*key) != nullptr; if (rc) unsetenv(*key); #else String::Value key(property); WCHAR* key_ptr = reinterpret_cast<WCHAR*>(*key); - if (key_ptr[0] == L'=' || !SetEnvironmentVariableW(key_ptr, NULL)) { + if (key_ptr[0] == L'=' || !SetEnvironmentVariableW(key_ptr, nullptr)) { // Deletion failed. Return true if the key wasn't there in the first place, // false if it is still there. - rc = GetEnvironmentVariableW(key_ptr, NULL, NULL) == 0 && + rc = GetEnvironmentVariableW(key_ptr, nullptr, 0) == 0 && GetLastError() != ERROR_SUCCESS; } #endif @@ -2412,12 +2414,12 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { } #else // _WIN32 WCHAR* environment = GetEnvironmentStringsW(); - if (environment == NULL) + if (environment == nullptr) return; // This should not happen. Local<Array> envarr = Array::New(env->isolate()); WCHAR* p = environment; int i = 0; - while (*p != NULL) { + while (*p != nullptr) { WCHAR *s; if (*p == L'=') { // If the key starts with '=' it is a hidden environment variable. @@ -2483,7 +2485,8 @@ static Handle<Object> GetFeatures(Environment* env) { obj->Set(env->tls_ocsp_string(), tls_ocsp); obj->Set(env->tls_string(), - Boolean::New(env->isolate(), get_builtin_module("crypto") != NULL)); + Boolean::New(env->isolate(), + get_builtin_module("crypto") != nullptr)); return scope.Escape(obj); } @@ -2901,7 +2904,7 @@ void LoadEnvironment(Environment* env) { static void PrintHelp(); static bool ParseDebugOpt(const char* arg) { - const char* port = NULL; + const char* port = nullptr; if (!strcmp(arg, "--debug")) { use_debug_agent = true; @@ -2921,7 +2924,7 @@ static bool ParseDebugOpt(const char* arg) { return false; } - if (port != NULL) { + if (port != nullptr) { debug_port = atoi(port); if (debug_port < 1024 || debug_port > 65535) { fprintf(stderr, "Debug port must be in range 1024 to 65535.\n"); @@ -3002,9 +3005,9 @@ static void ParseArgs(int* argc, const char** new_argv = new const char*[nargs]; for (unsigned int i = 0; i < nargs; ++i) { - new_exec_argv[i] = NULL; - new_v8_argv[i] = NULL; - new_argv[i] = NULL; + new_exec_argv[i] = nullptr; + new_v8_argv[i] = nullptr; + new_argv[i] = nullptr; } // exec_argv starts with the first option, the other two start with argv[0]. @@ -3032,19 +3035,19 @@ static void ParseArgs(int* argc, strcmp(arg, "--print") == 0 || strcmp(arg, "-pe") == 0 || strcmp(arg, "-p") == 0) { - bool is_eval = strchr(arg, 'e') != NULL; - bool is_print = strchr(arg, 'p') != NULL; + bool is_eval = strchr(arg, 'e') != nullptr; + bool is_print = strchr(arg, 'p') != nullptr; print_eval = print_eval || is_print; // --eval, -e and -pe always require an argument. if (is_eval == true) { args_consumed += 1; eval_string = argv[index + 1]; - if (eval_string == NULL) { + if (eval_string == nullptr) { fprintf(stderr, "%s: %s requires an argument\n", argv[0], arg); exit(9); } } else if ((index + 1 < nargs) && - argv[index + 1] != NULL && + argv[index + 1] != nullptr && argv[index + 1][0] != '-') { args_consumed += 1; eval_string = argv[index + 1]; @@ -3170,7 +3173,7 @@ static void InstallEarlyDebugSignalHandler() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = EarlyDebugSignalHandler; - sigaction(SIGUSR1, &sa, NULL); + sigaction(SIGUSR1, &sa, nullptr); } @@ -3189,7 +3192,7 @@ static void RegisterSignalHandler(int signal, sa.sa_handler = handler; sa.sa_flags = reset_handler ? SA_RESETHAND : 0; sigfillset(&sa.sa_mask); - CHECK_EQ(sigaction(signal, &sa, NULL), 0); + CHECK_EQ(sigaction(signal, &sa, nullptr), 0); } @@ -3252,12 +3255,12 @@ static int RegisterDebugSignalHandler() { } mapping_handle = CreateFileMappingW(INVALID_HANDLE_VALUE, - NULL, + nullptr, PAGE_READWRITE, 0, sizeof *handler, mapping_name); - if (mapping_handle == NULL) { + if (mapping_handle == nullptr) { return -1; } @@ -3267,7 +3270,7 @@ static int RegisterDebugSignalHandler() { 0, 0, sizeof *handler)); - if (handler == NULL) { + if (handler == nullptr) { CloseHandle(mapping_handle); return -1; } @@ -3284,11 +3287,11 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = args.GetIsolate(); DWORD pid; - HANDLE process = NULL; - HANDLE thread = NULL; - HANDLE mapping = NULL; + HANDLE process = nullptr; + HANDLE thread = nullptr; + HANDLE mapping = nullptr; wchar_t mapping_name[32]; - LPTHREAD_START_ROUTINE* handler = NULL; + LPTHREAD_START_ROUTINE* handler = nullptr; if (args.Length() != 1) { env->ThrowError("Invalid number of arguments."); @@ -3302,7 +3305,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { PROCESS_VM_READ, FALSE, pid); - if (process == NULL) { + if (process == nullptr) { isolate->ThrowException( WinapiErrnoException(isolate, GetLastError(), "OpenProcess")); goto out; @@ -3316,7 +3319,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { } mapping = OpenFileMappingW(FILE_MAP_READ, FALSE, mapping_name); - if (mapping == NULL) { + if (mapping == nullptr) { isolate->ThrowException(WinapiErrnoException(isolate, GetLastError(), "OpenFileMappingW")); @@ -3329,20 +3332,20 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { 0, 0, sizeof *handler)); - if (handler == NULL || *handler == NULL) { + if (handler == nullptr || *handler == nullptr) { isolate->ThrowException( WinapiErrnoException(isolate, GetLastError(), "MapViewOfFile")); goto out; } thread = CreateRemoteThread(process, - NULL, + nullptr, 0, *handler, - NULL, + nullptr, 0, - NULL); - if (thread == NULL) { + nullptr); + if (thread == nullptr) { isolate->ThrowException(WinapiErrnoException(isolate, GetLastError(), "CreateRemoteThread")); @@ -3358,13 +3361,13 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { } out: - if (process != NULL) + if (process != nullptr) CloseHandle(process); - if (thread != NULL) + if (thread != nullptr) CloseHandle(thread); - if (handler != NULL) + if (handler != nullptr) UnmapViewOfFile(handler); - if (mapping != NULL) + if (mapping != nullptr) CloseHandle(mapping); } #endif // _WIN32 @@ -3425,14 +3428,14 @@ void Init(int* argc, } #if defined(NODE_HAVE_I18N_SUPPORT) - if (icu_data_dir == NULL) { + if (icu_data_dir == nullptr) { // if the parameter isn't given, use the env variable. icu_data_dir = secure_getenv("NODE_ICU_DATA"); } // Initialize ICU. - // If icu_data_dir is NULL here, it will load the 'minimal' data. + // If icu_data_dir is nullptr here, it will load the 'minimal' data. if (!i18n::InitializeICUDirectory(icu_data_dir)) { - FatalError(NULL, "Could not initialize ICU " + FatalError(nullptr, "Could not initialize ICU " "(check NODE_ICU_DATA or --icu-data-dir parameters)"); } #endif @@ -3445,7 +3448,7 @@ void Init(int* argc, fprintf(stderr, "%s: bad option: %s\n", argv[0], v8_argv[i]); } delete[] v8_argv; - v8_argv = NULL; + v8_argv = nullptr; if (v8_argc > 1) { exit(9); @@ -3505,7 +3508,7 @@ static AtExitCallback* at_exit_functions_; // TODO(bnoordhuis) Turn into per-context event. void RunAtExit(Environment* env) { AtExitCallback* p = at_exit_functions_; - at_exit_functions_ = NULL; + at_exit_functions_ = nullptr; while (p) { AtExitCallback* q = p->next_; @@ -3636,19 +3639,19 @@ Environment* CreateEnvironment(Isolate* isolate, env->RegisterHandleCleanup( reinterpret_cast<uv_handle_t*>(env->immediate_check_handle()), HandleCleanup, - NULL); + nullptr); env->RegisterHandleCleanup( reinterpret_cast<uv_handle_t*>(env->immediate_idle_handle()), HandleCleanup, - NULL); + nullptr); env->RegisterHandleCleanup( reinterpret_cast<uv_handle_t*>(env->idle_prepare_handle()), HandleCleanup, - NULL); + nullptr); env->RegisterHandleCleanup( reinterpret_cast<uv_handle_t*>(env->idle_check_handle()), HandleCleanup, - NULL); + nullptr); if (v8_is_profiling) { StartProfilerIdleNotifier(env); @@ -3669,7 +3672,7 @@ Environment* CreateEnvironment(Isolate* isolate, int Start(int argc, char** argv) { const char* replaceInvalid = secure_getenv("NODE_INVALID_UTF8"); - if (replaceInvalid == NULL) + if (replaceInvalid == nullptr) WRITE_UTF8_FLAGS |= String::REPLACE_INVALID_UTF8; #if !defined(_WIN32) @@ -3744,16 +3747,16 @@ int Start(int argc, char** argv) { RunAtExit(env); env->Dispose(); - env = NULL; + env = nullptr; } - CHECK_NE(node_isolate, NULL); + CHECK_NE(node_isolate, nullptr); node_isolate->Dispose(); - node_isolate = NULL; + node_isolate = nullptr; V8::Dispose(); delete[] exec_argv; - exec_argv = NULL; + exec_argv = nullptr; return code; } diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 4df6217b28..4c1caeb6ec 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -46,7 +46,7 @@ char* obj_data = static_cast<char*>( \ obj->GetIndexedPropertiesExternalArrayData()); \ if (obj_length > 0) \ - CHECK_NE(obj_data, NULL); + CHECK_NE(obj_data, nullptr); #define SLICE_START_END(start_arg, end_arg, end_max) \ size_t start; \ @@ -151,10 +151,10 @@ Local<Object> New(Environment* env, size_t length) { char* data; if (length > 0) { data = static_cast<char*>(malloc(length)); - if (data == NULL) + if (data == nullptr) FatalError("node::Buffer::New(size_t)", "Out Of Memory"); } else { - data = NULL; + data = nullptr; } smalloc::Alloc(env, obj, data, length); @@ -187,11 +187,11 @@ Local<Object> New(Environment* env, const char* data, size_t length) { char* new_data; if (length > 0) { new_data = static_cast<char*>(malloc(length)); - if (new_data == NULL) + if (new_data == nullptr) FatalError("node::Buffer::New(const char*, size_t)", "Out Of Memory"); memcpy(new_data, data, length); } else { - new_data = NULL; + new_data = nullptr; } smalloc::Alloc(env, obj, new_data, length); @@ -410,7 +410,7 @@ void StringWrite(const FunctionCallbackInfo<Value>& args) { max_length, str, encoding, - NULL); + nullptr); args.GetReturnValue().Set(written); } diff --git a/src/node_contextify.cc b/src/node_contextify.cc index ce9d720689..ccb1df6eba 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -230,7 +230,7 @@ class ContextifyContext { object_template->SetAccessCheckCallbacks(GlobalPropertyNamedAccessCheck, GlobalPropertyIndexedAccessCheck); - Local<Context> ctx = Context::New(env->isolate(), NULL, object_template); + Local<Context> ctx = Context::New(env->isolate(), nullptr, object_template); if (!ctx.IsEmpty()) ctx->SetSecurityToken(env->context()->GetSecurityToken()); @@ -332,7 +332,7 @@ class ContextifyContext { FIXED_ONE_BYTE_STRING(isolate, "_contextifyHidden"); Local<Value> context_external_v = sandbox->GetHiddenValue(hidden_name); if (context_external_v.IsEmpty() || !context_external_v->IsExternal()) { - return NULL; + return nullptr; } Local<External> context_external = context_external_v.As<External>(); @@ -550,7 +550,7 @@ class ContextifyScript : public BaseObject { ContextifyContext* contextify_context = ContextifyContext::ContextFromContextifiedSandbox(env->isolate(), sandbox); - if (contextify_context == NULL) { + if (contextify_context == nullptr) { return env->ThrowTypeError( "sandbox argument must have been converted to a context."); } diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5d295df7cb..7575fff97a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -112,7 +112,7 @@ static uv_rwlock_t* locks; const char* root_certs[] = { #include "node_root_certs.h" // NOLINT(build/include_order) - NULL + nullptr }; X509_STORE* root_cert_store; @@ -200,9 +200,9 @@ static int CryptoPemCallback(char *buf, int size, int rwflag, void *u) { void ThrowCryptoError(Environment* env, unsigned long err, - const char* default_message = NULL) { + const char* default_message = nullptr) { HandleScope scope(env->isolate()); - if (err != 0 || default_message == NULL) { + if (err != 0 || default_message == nullptr) { char errmsg[128] = { 0 }; ERR_error_string_n(err, errmsg, sizeof(errmsg)); env->ThrowError(errmsg); @@ -371,7 +371,7 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) { SSL_CTX_sess_set_get_cb(sc->ctx_, SSLWrap<Connection>::GetSessionCallback); SSL_CTX_sess_set_new_cb(sc->ctx_, SSLWrap<Connection>::NewSessionCallback); - sc->ca_store_ = NULL; + sc->ca_store_ = nullptr; } @@ -380,7 +380,7 @@ void SecureContext::Init(const FunctionCallbackInfo<Value>& args) { static BIO* LoadBIO(Environment* env, Handle<Value> v) { BIO* bio = NodeBIO::New(); if (!bio) - return NULL; + return nullptr; HandleScope scope(env->isolate()); @@ -397,7 +397,7 @@ static BIO* LoadBIO(Environment* env, Handle<Value> v) { if (r <= 0) { BIO_free_all(bio); - return NULL; + return nullptr; } return bio; @@ -411,12 +411,12 @@ static X509* LoadX509(Environment* env, Handle<Value> v) { BIO *bio = LoadBIO(env, v); if (!bio) - return NULL; + return nullptr; - X509 * x509 = PEM_read_bio_X509(bio, NULL, CryptoPemCallback, NULL); + X509 * x509 = PEM_read_bio_X509(bio, nullptr, CryptoPemCallback, nullptr); if (!x509) { BIO_free_all(bio); - return NULL; + return nullptr; } BIO_free_all(bio); @@ -444,9 +444,9 @@ void SecureContext::SetKey(const FunctionCallbackInfo<Value>& args) { node::Utf8Value passphrase(args[1]); EVP_PKEY* key = PEM_read_bio_PrivateKey(bio, - NULL, + nullptr, CryptoPemCallback, - len == 1 ? NULL : *passphrase); + len == 1 ? nullptr : *passphrase); if (!key) { BIO_free_all(bio); @@ -469,7 +469,7 @@ int SSL_CTX_get_issuer(SSL_CTX* ctx, X509* cert, X509** issuer) { X509_STORE* store = SSL_CTX_get_cert_store(ctx); X509_STORE_CTX store_ctx; - ret = X509_STORE_CTX_init(&store_ctx, store, NULL, NULL); + ret = X509_STORE_CTX_init(&store_ctx, store, nullptr, nullptr); if (!ret) goto end; @@ -491,11 +491,11 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, X509** cert, X509** issuer) { int ret = 0; - X509* x = NULL; + X509* x = nullptr; - x = PEM_read_bio_X509_AUX(in, NULL, CryptoPemCallback, NULL); + x = PEM_read_bio_X509_AUX(in, nullptr, CryptoPemCallback, nullptr); - if (x == NULL) { + if (x == nullptr) { SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_PEM_LIB); goto end; } @@ -514,12 +514,12 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, int r; unsigned long err; - if (ctx->extra_certs != NULL) { + if (ctx->extra_certs != nullptr) { sk_X509_pop_free(ctx->extra_certs, X509_free); - ctx->extra_certs = NULL; + ctx->extra_certs = nullptr; } - while ((ca = PEM_read_bio_X509(in, NULL, CryptoPemCallback, NULL))) { + while ((ca = PEM_read_bio_X509(in, nullptr, CryptoPemCallback, nullptr))) { r = SSL_CTX_add_extra_chain_cert(ctx, ca); if (!r) { @@ -533,7 +533,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, // by SSL_CTX_use_certificate). // Find issuer - if (*issuer != NULL || X509_check_issued(ca, x) != X509_V_OK) + if (*issuer != nullptr || X509_check_issued(ca, x) != X509_V_OK) continue; *issuer = ca; } @@ -551,7 +551,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, // Try getting issuer from a cert store if (ret) { - if (*issuer == NULL) { + if (*issuer == nullptr) { ret = SSL_CTX_get_issuer(ctx, x, issuer); ret = ret < 0 ? 0 : 1; // NOTE: get_cert_store doesn't increment reference count, @@ -563,7 +563,7 @@ int SSL_CTX_use_certificate_chain(SSL_CTX* ctx, } end: - if (x != NULL) + if (x != nullptr) *cert = x; return ret; } @@ -645,9 +645,10 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) { if (!bio) return; - X509_CRL *x509 = PEM_read_bio_X509_CRL(bio, NULL, CryptoPemCallback, NULL); + X509_CRL *x509 = + PEM_read_bio_X509_CRL(bio, nullptr, CryptoPemCallback, nullptr); - if (x509 == NULL) { + if (x509 == nullptr) { BIO_free_all(bio); return; } @@ -664,7 +665,7 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) { void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { SecureContext* sc = Unwrap<SecureContext>(args.Holder()); - CHECK_EQ(sc->ca_store_, NULL); + CHECK_EQ(sc->ca_store_, nullptr); if (!root_cert_store) { root_cert_store = X509_STORE_new(); @@ -677,9 +678,9 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) { return; } - X509 *x509 = PEM_read_bio_X509(bp, NULL, CryptoPemCallback, NULL); + X509 *x509 = PEM_read_bio_X509(bp, nullptr, CryptoPemCallback, nullptr); - if (x509 == NULL) { + if (x509 == nullptr) { BIO_free_all(bp); return; } @@ -724,7 +725,7 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) { EC_KEY* ecdh = EC_KEY_new_by_curve_name(nid); - if (ecdh == NULL) + if (ecdh == nullptr) return env->ThrowTypeError("First argument should be a valid curve name"); SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_ECDH_USE); @@ -748,10 +749,10 @@ void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) { if (!bio) return; - DH* dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); + DH* dh = PEM_read_bio_DHparams(bio, nullptr, nullptr, nullptr); BIO_free_all(bio); - if (dh == NULL) + if (dh == nullptr) return; SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_DH_USE); @@ -796,7 +797,7 @@ void SecureContext::SetSessionIdContext( Local<String> message; bio = BIO_new(BIO_s_mem()); - if (bio == NULL) { + if (bio == nullptr) { message = FIXED_ONE_BYTE_STRING(args.GetIsolate(), "SSL_CTX_set_session_id_context error"); } else { @@ -832,12 +833,12 @@ void SecureContext::Close(const FunctionCallbackInfo<Value>& args) { void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - BIO* in = NULL; - PKCS12* p12 = NULL; - EVP_PKEY* pkey = NULL; - X509* cert = NULL; - STACK_OF(X509)* extraCerts = NULL; - char* pass = NULL; + BIO* in = nullptr; + PKCS12* p12 = nullptr; + EVP_PKEY* pkey = nullptr; + X509* cert = nullptr; + STACK_OF(X509)* extraCerts = nullptr; + char* pass = nullptr; bool ret = false; SecureContext* sc = Unwrap<SecureContext>(args.Holder()); @@ -847,7 +848,7 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) { } in = LoadBIO(env, args[0]); - if (in == NULL) { + if (in == nullptr) { return env->ThrowError("Unable to load BIO"); } @@ -952,10 +953,10 @@ void SecureContext::GetCertificate(const FunctionCallbackInfo<Value>& args) { cert = wrap->cert_; else cert = wrap->issuer_; - if (cert == NULL) + if (cert == nullptr) return args.GetReturnValue().Set(Null(env->isolate())); - int size = i2d_X509(cert, NULL); + int size = i2d_X509(cert, nullptr); Local<Object> buff = Buffer::New(env, size); unsigned char* serialized = reinterpret_cast<unsigned char*>( Buffer::Data(buff)); @@ -1010,16 +1011,16 @@ void SSLWrap<Base>::InitNPN(SecureContext* sc) { // Server should advertise NPN protocols SSL_CTX_set_next_protos_advertised_cb(sc->ctx_, AdvertiseNextProtoCallback, - NULL); + nullptr); // Client should select protocol from list of advertised // If server supports NPN - SSL_CTX_set_next_proto_select_cb(sc->ctx_, SelectNextProtoCallback, NULL); + SSL_CTX_set_next_proto_select_cb(sc->ctx_, SelectNextProtoCallback, nullptr); #endif // OPENSSL_NPN_NEGOTIATED #ifdef NODE__HAVE_TLSEXT_STATUS_CB // OCSP stapling SSL_CTX_set_tlsext_status_cb(sc->ctx_, TLSExtStatusCallback); - SSL_CTX_set_tlsext_status_arg(sc->ctx_, NULL); + SSL_CTX_set_tlsext_status_arg(sc->ctx_, nullptr); #endif // NODE__HAVE_TLSEXT_STATUS_CB } @@ -1033,7 +1034,7 @@ SSL_SESSION* SSLWrap<Base>::GetSessionCallback(SSL* s, *copy = 0; SSL_SESSION* sess = w->next_sess_; - w->next_sess_ = NULL; + w->next_sess_ = nullptr; return sess; } @@ -1050,7 +1051,7 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) { return 0; // Check if session is small enough to be stored - int size = i2d_SSL_SESSION(sess, NULL); + int size = i2d_SSL_SESSION(sess, nullptr); if (size > SecureContext::kMaxSessionSize) return 0; @@ -1086,7 +1087,7 @@ void SSLWrap<Base>::OnClientHello(void* arg, reinterpret_cast<const char*>(hello.session_id()), hello.session_size()); hello_obj->Set(env->session_id_string(), buff); - if (hello.servername() == NULL) { + if (hello.servername() == nullptr) { hello_obj->Set(env->servername_string(), String::Empty(env->isolate())); } else { Local<String> servername = OneByteString(env->isolate(), @@ -1144,7 +1145,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { int rv; ext = X509_get_ext(cert, index); - CHECK_NE(ext, NULL); + CHECK_NE(ext, nullptr); rv = X509V3_EXT_print(bio, ext, 0, 0); CHECK_EQ(rv, 1); @@ -1158,11 +1159,11 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { } EVP_PKEY* pkey = X509_get_pubkey(cert); - RSA* rsa = NULL; - if (pkey != NULL) + RSA* rsa = nullptr; + if (pkey != nullptr) rsa = EVP_PKEY_get1_RSA(pkey); - if (rsa != NULL) { + if (rsa != nullptr) { BN_print(bio, rsa->n); BIO_get_mem_ptr(bio, &mem); info->Set(env->modulus_string(), @@ -1178,13 +1179,13 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { (void) BIO_reset(bio); } - if (pkey != NULL) { + if (pkey != nullptr) { EVP_PKEY_free(pkey); - pkey = NULL; + pkey = nullptr; } - if (rsa != NULL) { + if (rsa != nullptr) { RSA_free(rsa); - rsa = NULL; + rsa = nullptr; } ASN1_TIME_print(bio, X509_get_notBefore(cert)); @@ -1225,8 +1226,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { } STACK_OF(ASN1_OBJECT)* eku = static_cast<STACK_OF(ASN1_OBJECT)*>( - X509_get_ext_d2i(cert, NID_ext_key_usage, NULL, NULL)); - if (eku != NULL) { + X509_get_ext_d2i(cert, NID_ext_key_usage, nullptr, nullptr)); + if (eku != nullptr) { Local<Array> ext_key_usage = Array::New(env->isolate()); char buf[256]; @@ -1241,7 +1242,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { } if (ASN1_INTEGER* serial_number = X509_get_serialNumber(cert)) { - if (BIGNUM* bn = ASN1_INTEGER_to_BN(serial_number, NULL)) { + if (BIGNUM* bn = ASN1_INTEGER_to_BN(serial_number, nullptr)) { if (char* buf = BN_bn2hex(bn)) { info->Set(env->serial_number_string(), OneByteString(env->isolate(), buf)); @@ -1252,7 +1253,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) { } // Raw DER certificate - int size = i2d_X509(cert, NULL); + int size = i2d_X509(cert, nullptr); Local<Object> buff = Buffer::New(env, size); unsigned char* serialized = reinterpret_cast<unsigned char*>( Buffer::Data(buff)); @@ -1278,29 +1279,29 @@ void SSLWrap<Base>::GetPeerCertificate( // NOTE: This is because of the odd OpenSSL behavior. On client `cert_chain` // contains the `peer_certificate`, but on server it doesn't - X509* cert = w->is_server() ? SSL_get_peer_certificate(w->ssl_) : NULL; + X509* cert = w->is_server() ? SSL_get_peer_certificate(w->ssl_) : nullptr; STACK_OF(X509)* ssl_certs = SSL_get_peer_cert_chain(w->ssl_); - STACK_OF(X509)* peer_certs = NULL; - if (cert == NULL && ssl_certs == NULL) + STACK_OF(X509)* peer_certs = nullptr; + if (cert == nullptr && ssl_certs == nullptr) goto done; - if (cert == NULL && sk_X509_num(ssl_certs) == 0) + if (cert == nullptr && sk_X509_num(ssl_certs) == 0) goto done; // Short result requested if (args.Length() < 1 || !args[0]->IsTrue()) { result = X509ToObject(env, - cert == NULL ? sk_X509_value(ssl_certs, 0) : cert); + cert == nullptr ? sk_X509_value(ssl_certs, 0) : cert); goto done; } // Clone `ssl_certs`, because we are going to destruct it - peer_certs = sk_X509_new(NULL); - if (cert != NULL) + peer_certs = sk_X509_new(nullptr); + if (cert != nullptr) sk_X509_push(peer_certs, cert); for (int i = 0; i < sk_X509_num(ssl_certs); i++) { cert = X509_dup(sk_X509_value(ssl_certs, i)); - if (cert == NULL) + if (cert == nullptr) goto done; if (!sk_X509_push(peer_certs, cert)) goto done; @@ -1358,11 +1359,11 @@ void SSLWrap<Base>::GetPeerCertificate( if (X509_check_issued(cert, cert) == X509_V_OK) info->Set(env->issuercert_string(), info); - CHECK_NE(cert, NULL); + CHECK_NE(cert, nullptr); X509_free(cert); done: - if (peer_certs != NULL) + if (peer_certs != nullptr) sk_X509_pop_free(peer_certs, X509_free); if (result.IsEmpty()) result = Object::New(env->isolate()); @@ -1377,10 +1378,10 @@ void SSLWrap<Base>::GetSession(const FunctionCallbackInfo<Value>& args) { Base* w = Unwrap<Base>(args.Holder()); SSL_SESSION* sess = SSL_get_session(w->ssl_); - if (sess == NULL) + if (sess == nullptr) return; - int slen = i2d_SSL_SESSION(sess, NULL); + int slen = i2d_SSL_SESSION(sess, nullptr); CHECK_GT(slen, 0); unsigned char* sbuf = new unsigned char[slen]; @@ -1408,11 +1409,11 @@ void SSLWrap<Base>::SetSession(const FunctionCallbackInfo<Value>& args) { memcpy(sbuf, Buffer::Data(args[0]), slen); const unsigned char* p = reinterpret_cast<const unsigned char*>(sbuf); - SSL_SESSION* sess = d2i_SSL_SESSION(NULL, &p, slen); + SSL_SESSION* sess = d2i_SSL_SESSION(nullptr, &p, slen); delete[] sbuf; - if (sess == NULL) + if (sess == nullptr) return; int r = SSL_set_session(w->ssl_, sess); @@ -1433,16 +1434,16 @@ void SSLWrap<Base>::LoadSession(const FunctionCallbackInfo<Value>& args) { char* sbuf = Buffer::Data(args[0]); const unsigned char* p = reinterpret_cast<unsigned char*>(sbuf); - SSL_SESSION* sess = d2i_SSL_SESSION(NULL, &p, slen); + SSL_SESSION* sess = d2i_SSL_SESSION(nullptr, &p, slen); // Setup next session and move hello to the BIO buffer - if (w->next_sess_ != NULL) + if (w->next_sess_ != nullptr) SSL_SESSION_free(w->next_sess_); w->next_sess_ = sess; Local<Object> info = Object::New(env->isolate()); #ifndef OPENSSL_NO_TLSEXT - if (sess->tlsext_hostname == NULL) { + if (sess->tlsext_hostname == nullptr) { info->Set(env->servername_string(), False(args.GetIsolate())); } else { info->Set(env->servername_string(), @@ -1496,7 +1497,7 @@ void SSLWrap<Base>::GetTLSTicket(const FunctionCallbackInfo<Value>& args) { Environment* env = w->ssl_env(); SSL_SESSION* sess = SSL_get_session(w->ssl_); - if (sess == NULL || sess->tlsext_tick == NULL) + if (sess == nullptr || sess->tlsext_tick == nullptr) return; Local<Object> buf = Buffer::New(env, @@ -1635,7 +1636,7 @@ void SSLWrap<Base>::GetCurrentCipher(const FunctionCallbackInfo<Value>& args) { Environment* env = w->ssl_env(); OPENSSL_CONST SSL_CIPHER* c = SSL_get_current_cipher(w->ssl_); - if (c == NULL) + if (c == nullptr) return; Local<Object> info = Object::New(env->isolate()); @@ -1777,7 +1778,7 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) { const unsigned char* resp; int len = SSL_get_tlsext_status_ocsp_resp(s, &resp); Local<Value> arg; - if (resp == NULL) { + if (resp == nullptr) { arg = Null(env->isolate()); } else { arg = Buffer::New( @@ -1801,7 +1802,7 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) { // OpenSSL takes control of the pointer after accepting it char* data = reinterpret_cast<char*>(malloc(len)); - CHECK_NE(data, NULL); + CHECK_NE(data, nullptr); memcpy(data, resp, len); if (!SSL_set_tlsext_status_ocsp_resp(s, data, len)) @@ -1933,7 +1934,7 @@ int Connection::HandleSSLError(const char* func, // into JavaScript. There is no test which demonstrates this problem. // https://github.com/joyent/node/issues/1719 bio = BIO_new(BIO_s_mem()); - if (bio != NULL) { + if (bio != nullptr) { ERR_print_errors(bio); BIO_get_mem_ptr(bio, &mem); Local<Value> exception = Exception::Error( @@ -1983,7 +1984,7 @@ void Connection::SetShutdownFlags() { void Connection::NewSessionDoneCb() { HandleScope scope(env()->isolate()); - MakeCallback(env()->onnewsessiondone_string(), 0, NULL); + MakeCallback(env()->onnewsessiondone_string(), 0, nullptr); } @@ -2181,11 +2182,11 @@ void Connection::SSLInfoCallback(const SSL *ssl_, int where, int ret) { Context::Scope context_scope(env->context()); if (where & SSL_CB_HANDSHAKE_START) { - conn->MakeCallback(env->onhandshakestart_string(), 0, NULL); + conn->MakeCallback(env->onhandshakestart_string(), 0, nullptr); } if (where & SSL_CB_HANDSHAKE_DONE) { - conn->MakeCallback(env->onhandshakedone_string(), 0, NULL); + conn->MakeCallback(env->onhandshakedone_string(), 0, nullptr); } } @@ -2417,9 +2418,9 @@ void Connection::Start(const FunctionCallbackInfo<Value>& args) { void Connection::Close(const FunctionCallbackInfo<Value>& args) { Connection* conn = Unwrap<Connection>(args.Holder()); - if (conn->ssl_ != NULL) { + if (conn->ssl_ != nullptr) { SSL_free(conn->ssl_); - conn->ssl_ = NULL; + conn->ssl_ = nullptr; } } @@ -2483,9 +2484,9 @@ void CipherBase::Init(const char* cipher_type, int key_buf_len) { HandleScope scope(env()->isolate()); - CHECK_EQ(cipher_, NULL); + CHECK_EQ(cipher_, nullptr); cipher_ = EVP_get_cipherbyname(cipher_type); - if (cipher_ == NULL) { + if (cipher_ == nullptr) { return env()->ThrowError("Unknown cipher"); } @@ -2494,7 +2495,7 @@ void CipherBase::Init(const char* cipher_type, int key_len = EVP_BytesToKey(cipher_, EVP_md5(), - NULL, + nullptr, reinterpret_cast<const unsigned char*>(key_buf), key_buf_len, 1, @@ -2502,15 +2503,16 @@ void CipherBase::Init(const char* cipher_type, iv); EVP_CIPHER_CTX_init(&ctx_); - EVP_CipherInit_ex(&ctx_, cipher_, NULL, NULL, NULL, kind_ == kCipher); + const bool encrypt = (kind_ == kCipher); + EVP_CipherInit_ex(&ctx_, cipher_, nullptr, nullptr, nullptr, encrypt); if (!EVP_CIPHER_CTX_set_key_length(&ctx_, key_len)) { EVP_CIPHER_CTX_cleanup(&ctx_); return env()->ThrowError("Invalid key length"); } EVP_CipherInit_ex(&ctx_, - NULL, - NULL, + nullptr, + nullptr, reinterpret_cast<unsigned char*>(key), reinterpret_cast<unsigned char*>(iv), kind_ == kCipher); @@ -2541,7 +2543,7 @@ void CipherBase::InitIv(const char* cipher_type, HandleScope scope(env()->isolate()); cipher_ = EVP_get_cipherbyname(cipher_type); - if (cipher_ == NULL) { + if (cipher_ == nullptr) { return env()->ThrowError("Unknown cipher"); } @@ -2552,15 +2554,16 @@ void CipherBase::InitIv(const char* cipher_type, return env()->ThrowError("Invalid IV length"); } EVP_CIPHER_CTX_init(&ctx_); - EVP_CipherInit_ex(&ctx_, cipher_, NULL, NULL, NULL, kind_ == kCipher); + const bool encrypt = (kind_ == kCipher); + EVP_CipherInit_ex(&ctx_, cipher_, nullptr, nullptr, nullptr, encrypt); if (!EVP_CIPHER_CTX_set_key_length(&ctx_, key_len)) { EVP_CIPHER_CTX_cleanup(&ctx_); return env()->ThrowError("Invalid key length"); } EVP_CipherInit_ex(&ctx_, - NULL, - NULL, + nullptr, + nullptr, reinterpret_cast<const unsigned char*>(key), reinterpret_cast<const unsigned char*>(iv), kind_ == kCipher); @@ -2612,7 +2615,7 @@ void CipherBase::GetAuthTag(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); CipherBase* cipher = Unwrap<CipherBase>(args.Holder()); - char* out = NULL; + char* out = nullptr; unsigned int out_len = 0; if (cipher->GetAuthTag(&out, &out_len)) { @@ -2654,7 +2657,7 @@ bool CipherBase::SetAAD(const char* data, unsigned int len) { return false; int outlen; if (!EVP_CipherUpdate(&ctx_, - NULL, + nullptr, &outlen, reinterpret_cast<const unsigned char*>(data), len)) { @@ -2684,13 +2687,13 @@ bool CipherBase::Update(const char* data, return 0; // on first update: - if (kind_ == kDecipher && IsAuthenticatedMode() && auth_tag_ != NULL) { + if (kind_ == kDecipher && IsAuthenticatedMode() && auth_tag_ != nullptr) { EVP_CIPHER_CTX_ctrl(&ctx_, EVP_CTRL_GCM_SET_TAG, auth_tag_len_, reinterpret_cast<unsigned char*>(auth_tag_)); delete[] auth_tag_; - auth_tag_ = NULL; + auth_tag_ = nullptr; } *out_len = len + EVP_CIPHER_CTX_block_size(&ctx_); @@ -2710,7 +2713,7 @@ void CipherBase::Update(const FunctionCallbackInfo<Value>& args) { ASSERT_IS_STRING_OR_BUFFER(args[0]); - unsigned char* out = NULL; + unsigned char* out = nullptr; bool r; int out_len = 0; @@ -2772,7 +2775,7 @@ bool CipherBase::Final(unsigned char** out, int *out_len) { if (r && kind_ == kCipher) { delete[] auth_tag_; - auth_tag_ = NULL; + auth_tag_ = nullptr; if (IsAuthenticatedMode()) { auth_tag_len_ = EVP_GCM_TLS_TAG_LEN; // use default tag length auth_tag_ = new char[auth_tag_len_]; @@ -2796,7 +2799,7 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) { CipherBase* cipher = Unwrap<CipherBase>(args.Holder()); - unsigned char* out_value = NULL; + unsigned char* out_value = nullptr; int out_len = -1; Local<Value> outString; @@ -2804,7 +2807,7 @@ void CipherBase::Final(const FunctionCallbackInfo<Value>& args) { if (out_len <= 0 || !r) { delete[] out_value; - out_value = NULL; + out_value = nullptr; out_len = 0; if (!r) { const char* msg = cipher->IsAuthenticatedMode() ? @@ -2845,9 +2848,9 @@ void Hmac::New(const FunctionCallbackInfo<Value>& args) { void Hmac::HmacInit(const char* hash_type, const char* key, int key_len) { HandleScope scope(env()->isolate()); - CHECK_EQ(md_, NULL); + CHECK_EQ(md_, nullptr); md_ = EVP_get_digestbyname(hash_type); - if (md_ == NULL) { + if (md_ == nullptr) { return env()->ThrowError("Unknown message digest"); } HMAC_CTX_init(&ctx_); @@ -2941,12 +2944,12 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) { encoding = ParseEncoding(env->isolate(), args[0]->ToString(), BUFFER); } - unsigned char* md_value = NULL; + unsigned char* md_value = nullptr; unsigned int md_len = 0; bool r = hmac->HmacDigest(&md_value, &md_len); if (!r) { - md_value = NULL; + md_value = nullptr; md_len = 0; } @@ -2988,12 +2991,12 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) { bool Hash::HashInit(const char* hash_type) { - CHECK_EQ(md_, NULL); + CHECK_EQ(md_, nullptr); md_ = EVP_get_digestbyname(hash_type); - if (md_ == NULL) + if (md_ == nullptr) return false; EVP_MD_CTX_init(&mdctx_); - EVP_DigestInit_ex(&mdctx_, md_, NULL); + EVP_DigestInit_ex(&mdctx_, md_, nullptr); initialised_ = true; return true; } @@ -3131,13 +3134,13 @@ void Sign::New(const FunctionCallbackInfo<Value>& args) { SignBase::Error Sign::SignInit(const char* sign_type) { - CHECK_EQ(md_, NULL); + CHECK_EQ(md_, nullptr); md_ = EVP_get_digestbyname(sign_type); if (!md_) return kSignUnknownDigest; EVP_MD_CTX_init(&mdctx_); - if (!EVP_SignInit_ex(&mdctx_, md_, NULL)) + if (!EVP_SignInit_ex(&mdctx_, md_, nullptr)) return kSignInit; initialised_ = true; @@ -3207,19 +3210,19 @@ SignBase::Error Sign::SignFinal(const char* key_pem, if (!initialised_) return kSignNotInitialised; - BIO* bp = NULL; - EVP_PKEY* pkey = NULL; + BIO* bp = nullptr; + EVP_PKEY* pkey = nullptr; bool fatal = true; bp = BIO_new_mem_buf(const_cast<char*>(key_pem), key_pem_len); - if (bp == NULL) + if (bp == nullptr) goto exit; pkey = PEM_read_bio_PrivateKey(bp, - NULL, + nullptr, CryptoPemCallback, const_cast<char*>(passphrase)); - if (pkey == NULL) + if (pkey == nullptr) goto exit; if (EVP_SignFinal(&mdctx_, *sig, sig_len, pkey)) @@ -3228,9 +3231,9 @@ SignBase::Error Sign::SignFinal(const char* key_pem, initialised_ = false; exit: - if (pkey != NULL) + if (pkey != nullptr) EVP_PKEY_free(pkey); - if (bp != NULL) + if (bp != nullptr) BIO_free_all(bp); EVP_MD_CTX_cleanup(&mdctx_); @@ -3268,12 +3271,12 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) { Error err = sign->SignFinal( buf, buf_len, - len >= 3 && !args[2]->IsNull() ? *passphrase : NULL, + len >= 3 && !args[2]->IsNull() ? *passphrase : nullptr, &md_value, &md_len); if (err != kSignOk) { delete[] md_value; - md_value = NULL; + md_value = nullptr; md_len = 0; return sign->CheckThrow(err); } @@ -3308,13 +3311,13 @@ void Verify::New(const FunctionCallbackInfo<Value>& args) { SignBase::Error Verify::VerifyInit(const char* verify_type) { - CHECK_EQ(md_, NULL); + CHECK_EQ(md_, nullptr); md_ = EVP_get_digestbyname(verify_type); - if (md_ == NULL) + if (md_ == nullptr) return kSignUnknownDigest; EVP_MD_CTX_init(&mdctx_); - if (!EVP_VerifyInit_ex(&mdctx_, md_, NULL)) + if (!EVP_VerifyInit_ex(&mdctx_, md_, nullptr)) return kSignInit; initialised_ = true; @@ -3389,41 +3392,42 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem, ClearErrorOnReturn clear_error_on_return; (void) &clear_error_on_return; // Silence compiler warning. - EVP_PKEY* pkey = NULL; - BIO* bp = NULL; - X509* x509 = NULL; + EVP_PKEY* pkey = nullptr; + BIO* bp = nullptr; + X509* x509 = nullptr; bool fatal = true; int r = 0; bp = BIO_new_mem_buf(const_cast<char*>(key_pem), key_pem_len); - if (bp == NULL) + if (bp == nullptr) goto exit; // Check if this is a PKCS#8 or RSA public key before trying as X.509. // Split this out into a separate function once we have more than one // consumer of public keys. if (strncmp(key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0) { - pkey = PEM_read_bio_PUBKEY(bp, NULL, CryptoPemCallback, NULL); - if (pkey == NULL) + pkey = PEM_read_bio_PUBKEY(bp, nullptr, CryptoPemCallback, nullptr); + if (pkey == nullptr) goto exit; } else if (strncmp(key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0) { - RSA* rsa = PEM_read_bio_RSAPublicKey(bp, NULL, CryptoPemCallback, NULL); + RSA* rsa = + PEM_read_bio_RSAPublicKey(bp, nullptr, CryptoPemCallback, nullptr); if (rsa) { pkey = EVP_PKEY_new(); if (pkey) EVP_PKEY_set1_RSA(pkey, rsa); RSA_free(rsa); } - if (pkey == NULL) + if (pkey == nullptr) goto exit; } else { // X.509 fallback - x509 = PEM_read_bio_X509(bp, NULL, CryptoPemCallback, NULL); - if (x509 == NULL) + x509 = PEM_read_bio_X509(bp, nullptr, CryptoPemCallback, nullptr); + if (x509 == nullptr) goto exit; pkey = X509_get_pubkey(x509); - if (pkey == NULL) + if (pkey == nullptr) goto exit; } @@ -3434,11 +3438,11 @@ SignBase::Error Verify::VerifyFinal(const char* key_pem, pkey); exit: - if (pkey != NULL) + if (pkey != nullptr) EVP_PKEY_free(pkey); - if (bp != NULL) + if (bp != nullptr) BIO_free_all(bp); - if (x509 != NULL) + if (x509 != nullptr) X509_free(x509); EVP_MD_CTX_cleanup(&mdctx_); @@ -3505,53 +3509,53 @@ bool PublicKeyCipher::Cipher(const char* key_pem, int len, unsigned char** out, size_t* out_len) { - EVP_PKEY* pkey = NULL; - EVP_PKEY_CTX* ctx = NULL; - BIO* bp = NULL; - X509* x509 = NULL; + EVP_PKEY* pkey = nullptr; + EVP_PKEY_CTX* ctx = nullptr; + BIO* bp = nullptr; + X509* x509 = nullptr; bool fatal = true; bp = BIO_new_mem_buf(const_cast<char*>(key_pem), key_pem_len); - if (bp == NULL) + if (bp == nullptr) goto exit; // Check if this is a PKCS#8 or RSA public key before trying as X.509 and // private key. if (operation == kEncrypt && strncmp(key_pem, PUBLIC_KEY_PFX, PUBLIC_KEY_PFX_LEN) == 0) { - pkey = PEM_read_bio_PUBKEY(bp, NULL, NULL, NULL); - if (pkey == NULL) + pkey = PEM_read_bio_PUBKEY(bp, nullptr, nullptr, nullptr); + if (pkey == nullptr) goto exit; } else if (operation == kEncrypt && strncmp(key_pem, PUBRSA_KEY_PFX, PUBRSA_KEY_PFX_LEN) == 0) { - RSA* rsa = PEM_read_bio_RSAPublicKey(bp, NULL, NULL, NULL); + RSA* rsa = PEM_read_bio_RSAPublicKey(bp, nullptr, nullptr, nullptr); if (rsa) { pkey = EVP_PKEY_new(); if (pkey) EVP_PKEY_set1_RSA(pkey, rsa); RSA_free(rsa); } - if (pkey == NULL) + if (pkey == nullptr) goto exit; } else if (operation == kEncrypt && strncmp(key_pem, CERTIFICATE_PFX, CERTIFICATE_PFX_LEN) == 0) { - x509 = PEM_read_bio_X509(bp, NULL, CryptoPemCallback, NULL); - if (x509 == NULL) + x509 = PEM_read_bio_X509(bp, nullptr, CryptoPemCallback, nullptr); + if (x509 == nullptr) goto exit; pkey = X509_get_pubkey(x509); - if (pkey == NULL) + if (pkey == nullptr) goto exit; } else { pkey = PEM_read_bio_PrivateKey(bp, - NULL, + nullptr, CryptoPemCallback, const_cast<char*>(passphrase)); - if (pkey == NULL) + if (pkey == nullptr) goto exit; } - ctx = EVP_PKEY_CTX_new(pkey, NULL); + ctx = EVP_PKEY_CTX_new(pkey, nullptr); if (!ctx) goto exit; if (EVP_PKEY_cipher_init(ctx) <= 0) @@ -3559,7 +3563,7 @@ bool PublicKeyCipher::Cipher(const char* key_pem, if (EVP_PKEY_CTX_set_rsa_padding(ctx, padding) <= 0) goto exit; - if (EVP_PKEY_cipher(ctx, NULL, out_len, data, len) <= 0) + if (EVP_PKEY_cipher(ctx, nullptr, out_len, data, len) <= 0) goto exit; *out = new unsigned char[*out_len]; @@ -3570,11 +3574,11 @@ bool PublicKeyCipher::Cipher(const char* key_pem, fatal = false; exit: - if (pkey != NULL) + if (pkey != nullptr) EVP_PKEY_free(pkey); - if (bp != NULL) + if (bp != nullptr) BIO_free_all(bp); - if (ctx != NULL) + if (ctx != nullptr) EVP_PKEY_CTX_free(ctx); return !fatal; @@ -3599,13 +3603,13 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) { String::Utf8Value passphrase(args[3]); - unsigned char* out_value = NULL; + unsigned char* out_value = nullptr; size_t out_len = 0; bool r = Cipher<operation, EVP_PKEY_cipher_init, EVP_PKEY_cipher>( kbuf, klen, - args.Length() >= 3 && !args[2]->IsNull() ? *passphrase : NULL, + args.Length() >= 3 && !args[2]->IsNull() ? *passphrase : nullptr, padding, reinterpret_cast<const unsigned char*>(buf), len, @@ -3614,7 +3618,7 @@ void PublicKeyCipher::Cipher(const FunctionCallbackInfo<Value>& args) { if (out_len == 0 || !r) { delete[] out_value; - out_value = NULL; + out_value = nullptr; out_len = 0; if (!r) { return ThrowCryptoError(env, @@ -3647,7 +3651,7 @@ void DiffieHellman::Initialize(Environment* env, Handle<Object> target) { t->InstanceTemplate()->SetAccessor(env->verify_error_string(), DiffieHellman::VerifyErrorGetter, - NULL, + nullptr, Handle<Value>(), v8::DEFAULT, attributes); @@ -3667,7 +3671,7 @@ void DiffieHellman::Initialize(Environment* env, Handle<Object> target) { t2->InstanceTemplate()->SetAccessor(env->verify_error_string(), DiffieHellman::VerifyErrorGetter, - NULL, + nullptr, Handle<Value>(), v8::DEFAULT, attributes); @@ -3845,7 +3849,7 @@ void DiffieHellman::GetPublicKey(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("Not initialized"); } - if (diffieHellman->dh->pub_key == NULL) { + if (diffieHellman->dh->pub_key == nullptr) { return env->ThrowError("No public key - did you forget to generate one?"); } @@ -3868,7 +3872,7 @@ void DiffieHellman::GetPrivateKey(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("Not initialized"); } - if (diffieHellman->dh->priv_key == NULL) { + if (diffieHellman->dh->priv_key == nullptr) { return env->ThrowError("No private key - did you forget to generate one?"); } @@ -3893,7 +3897,7 @@ void DiffieHellman::ComputeSecret(const FunctionCallbackInfo<Value>& args) { ClearErrorOnReturn clear_error_on_return; (void) &clear_error_on_return; // Silence compiler warning. - BIGNUM* key = NULL; + BIGNUM* key = nullptr; if (args.Length() == 0) { return env->ThrowError("First argument must be other party's public key"); @@ -4045,7 +4049,7 @@ void ECDH::New(const FunctionCallbackInfo<Value>& args) { return env->ThrowTypeError("First argument should be a valid curve name"); EC_KEY* key = EC_KEY_new_by_curve_name(nid); - if (key == NULL) + if (key == nullptr) return env->ThrowError("Failed to create EC_KEY using curve name"); new ECDH(env, args.This(), key); @@ -4069,9 +4073,9 @@ EC_POINT* ECDH::BufferToPoint(char* data, size_t len) { int r; pub = EC_POINT_new(group_); - if (pub == NULL) { + if (pub == nullptr) { env()->ThrowError("Failed to allocate EC_POINT for a public key"); - return NULL; + return nullptr; } r = EC_POINT_oct2point( @@ -4079,7 +4083,7 @@ EC_POINT* ECDH::BufferToPoint(char* data, size_t len) { pub, reinterpret_cast<unsigned char*>(data), len, - NULL); + nullptr); if (!r) { env()->ThrowError("Failed to translate Buffer to a EC_POINT"); goto fatal; @@ -4089,7 +4093,7 @@ EC_POINT* ECDH::BufferToPoint(char* data, size_t len) { fatal: EC_POINT_free(pub); - return NULL; + return nullptr; } @@ -4102,16 +4106,16 @@ void ECDH::ComputeSecret(const FunctionCallbackInfo<Value>& args) { EC_POINT* pub = ecdh->BufferToPoint(Buffer::Data(args[0]), Buffer::Length(args[0])); - if (pub == NULL) + if (pub == nullptr) return; // NOTE: field_size is in bits int field_size = EC_GROUP_get_degree(ecdh->group_); size_t out_len = (field_size + 7) / 8; char* out = static_cast<char*>(malloc(out_len)); - CHECK_NE(out, NULL); + CHECK_NE(out, nullptr); - int r = ECDH_compute_key(out, out_len, pub, ecdh->key_, NULL); + int r = ECDH_compute_key(out, out_len, pub, ecdh->key_, nullptr); EC_POINT_free(pub); if (!r) { free(out); @@ -4134,21 +4138,21 @@ void ECDH::GetPublicKey(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("You should generate ECDH keys first"); const EC_POINT* pub = EC_KEY_get0_public_key(ecdh->key_); - if (pub == NULL) + if (pub == nullptr) return env->ThrowError("Failed to get ECDH public key"); int size; point_conversion_form_t form = static_cast<point_conversion_form_t>(args[0]->Uint32Value()); - size = EC_POINT_point2oct(ecdh->group_, pub, form, NULL, 0, NULL); + size = EC_POINT_point2oct(ecdh->group_, pub, form, nullptr, 0, nullptr); if (size == 0) return env->ThrowError("Failed to get public key length"); unsigned char* out = static_cast<unsigned char*>(malloc(size)); - CHECK_NE(out, NULL); + CHECK_NE(out, nullptr); - int r = EC_POINT_point2oct(ecdh->group_, pub, form, out, size, NULL); + int r = EC_POINT_point2oct(ecdh->group_, pub, form, out, size, nullptr); if (r != size) { free(out); return env->ThrowError("Failed to get public key"); @@ -4169,12 +4173,12 @@ void ECDH::GetPrivateKey(const FunctionCallbackInfo<Value>& args) { return env->ThrowError("You should generate ECDH keys first"); const BIGNUM* b = EC_KEY_get0_private_key(ecdh->key_); - if (b == NULL) + if (b == nullptr) return env->ThrowError("Failed to get ECDH private key"); int size = BN_num_bytes(b); unsigned char* out = static_cast<unsigned char*>(malloc(size)); - CHECK_NE(out, NULL); + CHECK_NE(out, nullptr); if (size != BN_bn2bin(b, out)) { free(out); @@ -4197,8 +4201,8 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) { BIGNUM* priv = BN_bin2bn( reinterpret_cast<unsigned char*>(Buffer::Data(args[0].As<Object>())), Buffer::Length(args[0].As<Object>()), - NULL); - if (priv == NULL) + nullptr); + if (priv == nullptr) return env->ThrowError("Failed to convert Buffer to BN"); if (!EC_KEY_set_private_key(ecdh->key_, priv)) @@ -4215,7 +4219,7 @@ void ECDH::SetPublicKey(const FunctionCallbackInfo<Value>& args) { EC_POINT* pub = ecdh->BufferToPoint(Buffer::Data(args[0].As<Object>()), Buffer::Length(args[0].As<Object>())); - if (pub == NULL) + if (pub == nullptr) return; int r = EC_KEY_set_public_key(ecdh->key_, pub); @@ -4246,7 +4250,7 @@ class PBKDF2Request : public AsyncWrap { keylen_(keylen), key_(static_cast<char*>(malloc(keylen))), iter_(iter) { - if (key() == NULL) + if (key() == nullptr) FatalError("node::PBKDF2Request()", "Out of Memory"); } @@ -4372,15 +4376,15 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) { void PBKDF2(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); - const EVP_MD* digest = NULL; - const char* type_error = NULL; - char* pass = NULL; - char* salt = NULL; + const EVP_MD* digest = nullptr; + const char* type_error = nullptr; + char* pass = nullptr; + char* salt = nullptr; ssize_t passlen = -1; ssize_t saltlen = -1; ssize_t keylen = -1; ssize_t iter = -1; - PBKDF2Request* req = NULL; + PBKDF2Request* req = nullptr; Local<Object> obj; if (args.Length() != 5 && args.Length() != 6) { @@ -4398,7 +4402,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { ASSERT_IS_BUFFER(args[1]); pass = static_cast<char*>(malloc(passlen)); - if (pass == NULL) { + if (pass == nullptr) { FatalError("node::PBKDF2()", "Out of Memory"); } memcpy(pass, Buffer::Data(args[0]), passlen); @@ -4410,7 +4414,7 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { } salt = static_cast<char*>(malloc(saltlen)); - if (salt == NULL) { + if (salt == nullptr) { FatalError("node::PBKDF2()", "Out of Memory"); } memcpy(salt, Buffer::Data(args[1]), saltlen); @@ -4440,13 +4444,13 @@ void PBKDF2(const FunctionCallbackInfo<Value>& args) { if (args[4]->IsString()) { node::Utf8Value digest_name(args[4]); digest = EVP_get_digestbyname(*digest_name); - if (digest == NULL) { + if (digest == nullptr) { type_error = "Bad digest name"; goto err; } } - if (digest == NULL) { + if (digest == nullptr) { digest = EVP_sha1(); } @@ -4496,7 +4500,7 @@ class RandomBytesRequest : public AsyncWrap { error_(0), size_(size), data_(static_cast<char*>(malloc(size))) { - if (data() == NULL) + if (data() == nullptr) FatalError("node::RandomBytesRequest()", "Out of Memory"); } @@ -4523,7 +4527,7 @@ class RandomBytesRequest : public AsyncWrap { inline void return_memory(char** d, size_t* len) { *d = data_; - data_ = NULL; + data_ = nullptr; *len = size_; size_ = 0; } @@ -4583,7 +4587,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local<Value> argv[2]) { argv[1] = Null(req->env()->isolate()); req->release(); } else { - char* data = NULL; + char* data = nullptr; size_t size; req->return_memory(&data, &size); argv[0] = Null(req->env()->isolate()); @@ -4652,12 +4656,12 @@ void GetSSLCiphers(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); SSL_CTX* ctx = SSL_CTX_new(TLSv1_server_method()); - if (ctx == NULL) { + if (ctx == nullptr) { return env->ThrowError("SSL_CTX_new() failed."); } SSL* ssl = SSL_new(ctx); - if (ssl == NULL) { + if (ssl == nullptr) { SSL_CTX_free(ctx); return env->ThrowError("SSL_new() failed."); } @@ -4743,24 +4747,24 @@ void Certificate::New(const FunctionCallbackInfo<Value>& args) { bool Certificate::VerifySpkac(const char* data, unsigned int len) { bool i = 0; - EVP_PKEY* pkey = NULL; - NETSCAPE_SPKI* spki = NULL; + EVP_PKEY* pkey = nullptr; + NETSCAPE_SPKI* spki = nullptr; spki = NETSCAPE_SPKI_b64_decode(data, len); - if (spki == NULL) + if (spki == nullptr) goto exit; pkey = X509_PUBKEY_get(spki->spkac->pubkey); - if (pkey == NULL) + if (pkey == nullptr) goto exit; i = NETSCAPE_SPKI_verify(spki, pkey) > 0; exit: - if (pkey != NULL) + if (pkey != nullptr) EVP_PKEY_free(pkey); - if (spki != NULL) + if (spki != nullptr) NETSCAPE_SPKI_free(spki); return i; @@ -4782,7 +4786,7 @@ void Certificate::VerifySpkac(const FunctionCallbackInfo<Value>& args) { return args.GetReturnValue().Set(i); char* data = Buffer::Data(args[0]); - CHECK_NE(data, NULL); + CHECK_NE(data, nullptr); i = certificate->VerifySpkac(data, length); @@ -4791,20 +4795,20 @@ void Certificate::VerifySpkac(const FunctionCallbackInfo<Value>& args) { const char* Certificate::ExportPublicKey(const char* data, int len) { - char* buf = NULL; - EVP_PKEY* pkey = NULL; - NETSCAPE_SPKI* spki = NULL; + char* buf = nullptr; + EVP_PKEY* pkey = nullptr; + NETSCAPE_SPKI* spki = nullptr; BIO* bio = BIO_new(BIO_s_mem()); - if (bio == NULL) + if (bio == nullptr) goto exit; spki = NETSCAPE_SPKI_b64_decode(data, len); - if (spki == NULL) + if (spki == nullptr) goto exit; pkey = NETSCAPE_SPKI_get_pubkey(spki); - if (pkey == NULL) + if (pkey == nullptr) goto exit; if (PEM_write_bio_PUBKEY(bio, pkey) <= 0) @@ -4818,13 +4822,13 @@ const char* Certificate::ExportPublicKey(const char* data, int len) { memcpy(buf, ptr->data, ptr->length); exit: - if (pkey != NULL) + if (pkey != nullptr) EVP_PKEY_free(pkey); - if (spki != NULL) + if (spki != nullptr) NETSCAPE_SPKI_free(spki); - if (bio != NULL) + if (bio != nullptr) BIO_free_all(bio); return buf; @@ -4846,10 +4850,10 @@ void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) { return args.GetReturnValue().SetEmptyString(); char* data = Buffer::Data(args[0]); - CHECK_NE(data, NULL); + CHECK_NE(data, nullptr); const char* pkey = certificate->ExportPublicKey(data, length); - if (pkey == NULL) + if (pkey == nullptr) return args.GetReturnValue().SetEmptyString(); Local<Value> out = Encode(env->isolate(), pkey, strlen(pkey), BUFFER); @@ -4861,13 +4865,13 @@ void Certificate::ExportPublicKey(const FunctionCallbackInfo<Value>& args) { const char* Certificate::ExportChallenge(const char* data, int len) { - NETSCAPE_SPKI* sp = NULL; + NETSCAPE_SPKI* sp = nullptr; sp = NETSCAPE_SPKI_b64_decode(data, len); - if (sp == NULL) - return NULL; + if (sp == nullptr) + return nullptr; - const char* buf = NULL; + const char* buf = nullptr; buf = reinterpret_cast<const char*>(ASN1_STRING_data(sp->spkac->challenge)); return buf; @@ -4889,10 +4893,10 @@ void Certificate::ExportChallenge(const FunctionCallbackInfo<Value>& args) { return args.GetReturnValue().SetEmptyString(); char* data = Buffer::Data(args[0]); - CHECK_NE(data, NULL); + CHECK_NE(data, nullptr); const char* cert = crt->ExportChallenge(data, len); - if (cert == NULL) + if (cert == nullptr) return args.GetReturnValue().SetEmptyString(); Local<Value> outString = Encode(env->isolate(), cert, strlen(cert), BUFFER); @@ -4943,18 +4947,18 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) { ENGINE* engine = ENGINE_by_id(*engine_id); // Engine not found, try loading dynamically - if (engine == NULL) { + if (engine == nullptr) { engine = ENGINE_by_id("dynamic"); - if (engine != NULL) { + if (engine != nullptr) { if (!ENGINE_ctrl_cmd_string(engine, "SO_PATH", *engine_id, 0) || - !ENGINE_ctrl_cmd_string(engine, "LOAD", NULL, 0)) { + !ENGINE_ctrl_cmd_string(engine, "LOAD", nullptr, 0)) { ENGINE_free(engine); - engine = NULL; + engine = nullptr; } } } - if (engine == NULL) { + if (engine == nullptr) { int err = ERR_get_error(); if (err == 0) { char tmp[1024]; diff --git a/src/node_crypto.h b/src/node_crypto.h index 12b5eafb18..3c78ed6744 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -113,10 +113,10 @@ class SecureContext : public BaseObject { SecureContext(Environment* env, v8::Local<v8::Object> wrap) : BaseObject(env, wrap), - ca_store_(NULL), - ctx_(NULL), - cert_(NULL), - issuer_(NULL) { + ca_store_(nullptr), + ctx_(nullptr), + cert_(nullptr), + issuer_(nullptr) { MakeWeak<SecureContext>(this); } @@ -127,19 +127,19 @@ class SecureContext : public BaseObject { // Since we want our root_cert_store to stay around forever // we just clear the field. Hopefully OpenSSL will not modify this // struct in future versions. - ctx_->cert_store = NULL; + ctx_->cert_store = nullptr; } SSL_CTX_free(ctx_); - if (cert_ != NULL) + if (cert_ != nullptr) X509_free(cert_); - if (issuer_ != NULL) + if (issuer_ != nullptr) X509_free(issuer_); - ctx_ = NULL; - ca_store_ = NULL; - cert_ = NULL; - issuer_ = NULL; + ctx_ = nullptr; + ca_store_ = nullptr; + cert_ = nullptr; + issuer_ = nullptr; } else { - CHECK_EQ(ca_store_, NULL); + CHECK_EQ(ca_store_, nullptr); } } }; @@ -157,21 +157,21 @@ class SSLWrap { SSLWrap(Environment* env, SecureContext* sc, Kind kind) : env_(env), kind_(kind), - next_sess_(NULL), + next_sess_(nullptr), session_callbacks_(false), new_session_wait_(false) { ssl_ = SSL_new(sc->ctx_); - CHECK_NE(ssl_, NULL); + CHECK_NE(ssl_, nullptr); } ~SSLWrap() { - if (ssl_ != NULL) { + if (ssl_ != nullptr) { SSL_free(ssl_); - ssl_ = NULL; + ssl_ = nullptr; } - if (next_sess_ != NULL) { + if (next_sess_ != nullptr) { SSL_SESSION_free(next_sess_); - next_sess_ = NULL; + next_sess_ = nullptr; } #ifdef OPENSSL_NPN_NEGOTIATED @@ -336,8 +336,8 @@ class Connection : public SSLWrap<Connection>, public AsyncWrap { SSLWrap<Connection>::Kind kind) : SSLWrap<Connection>(env, sc, kind), AsyncWrap(env, wrap, AsyncWrap::PROVIDER_CRYPTO), - bio_read_(NULL), - bio_write_(NULL), + bio_read_(nullptr), + bio_write_(nullptr), hello_offset_(0) { MakeWeak<Connection>(this); hello_parser_.Start(SSLWrap<Connection>::OnClientHello, @@ -406,10 +406,10 @@ class CipherBase : public BaseObject { v8::Local<v8::Object> wrap, CipherKind kind) : BaseObject(env, wrap), - cipher_(NULL), + cipher_(nullptr), initialised_(false), kind_(kind), - auth_tag_(NULL), + auth_tag_(nullptr), auth_tag_len_(0) { MakeWeak<CipherBase>(this); } @@ -445,7 +445,7 @@ class Hmac : public BaseObject { Hmac(Environment* env, v8::Local<v8::Object> wrap) : BaseObject(env, wrap), - md_(NULL), + md_(nullptr), initialised_(false) { MakeWeak<Hmac>(this); } @@ -476,7 +476,7 @@ class Hash : public BaseObject { Hash(Environment* env, v8::Local<v8::Object> wrap) : BaseObject(env, wrap), - md_(NULL), + md_(nullptr), initialised_(false) { MakeWeak<Hash>(this); } @@ -501,7 +501,7 @@ class SignBase : public BaseObject { SignBase(Environment* env, v8::Local<v8::Object> wrap) : BaseObject(env, wrap), - md_(NULL), + md_(nullptr), initialised_(false) { } @@ -599,7 +599,7 @@ class PublicKeyCipher { class DiffieHellman : public BaseObject { public: ~DiffieHellman() { - if (dh != NULL) { + if (dh != nullptr) { DH_free(dh); } } @@ -630,7 +630,7 @@ class DiffieHellman : public BaseObject { : BaseObject(env, wrap), initialised_(false), verifyError_(0), - dh(NULL) { + dh(nullptr) { MakeWeak<DiffieHellman>(this); } @@ -645,10 +645,10 @@ class DiffieHellman : public BaseObject { class ECDH : public BaseObject { public: ~ECDH() { - if (key_ != NULL) + if (key_ != nullptr) EC_KEY_free(key_); - key_ = NULL; - group_ = NULL; + key_ = nullptr; + group_ = nullptr; } static void Initialize(Environment* env, v8::Handle<v8::Object> target); @@ -660,7 +660,7 @@ class ECDH : public BaseObject { key_(key), group_(EC_KEY_get0_group(key_)) { MakeWeak<ECDH>(this); - ASSERT(group_ != NULL); + ASSERT(group_ != nullptr); } static void New(const v8::FunctionCallbackInfo<v8::Value>& args); diff --git a/src/node_crypto_bio.cc b/src/node_crypto_bio.cc index 16ec515de9..e6ccb33f8f 100644 --- a/src/node_crypto_bio.cc +++ b/src/node_crypto_bio.cc @@ -37,7 +37,7 @@ const BIO_METHOD NodeBIO::method = { NodeBIO::Ctrl, NodeBIO::New, NodeBIO::Free, - NULL + nullptr }; @@ -61,13 +61,13 @@ int NodeBIO::New(BIO* bio) { int NodeBIO::Free(BIO* bio) { - if (bio == NULL) + if (bio == nullptr) return 0; if (bio->shutdown) { - if (bio->init && bio->ptr != NULL) { + if (bio->init && bio->ptr != nullptr) { delete FromBIO(bio); - bio->ptr = NULL; + bio->ptr = nullptr; } } @@ -151,7 +151,7 @@ int NodeBIO::Gets(BIO* bio, char* out, int size) { if (i < size && i >= 0 && static_cast<size_t>(i) < nbio->Length()) i++; - // Shift `i` a bit to NULL-terminate string later + // Shift `i` a bit to nullptr-terminate string later if (size == i) i--; @@ -183,8 +183,8 @@ long NodeBIO::Ctrl(BIO* bio, int cmd, long num, void* ptr) { break; case BIO_CTRL_INFO: ret = nbio->Length(); - if (ptr != NULL) - *reinterpret_cast<void**>(ptr) = NULL; + if (ptr != nullptr) + *reinterpret_cast<void**>(ptr) = nullptr; break; case BIO_C_SET_BUF_MEM: CHECK(0 && "Can't use SET_BUF_MEM_PTR with NodeBIO"); @@ -252,7 +252,7 @@ size_t NodeBIO::Read(char* out, size_t size) { avail = left; // Copy data - if (out != NULL) + if (out != nullptr) memcpy(out + offset, read_head_->data_ + read_head_->read_pos_, avail); read_head_->read_pos_ += avail; @@ -274,7 +274,7 @@ size_t NodeBIO::Read(char* out, size_t size) { void NodeBIO::FreeEmpty() { - if (write_head_ == NULL) + if (write_head_ == nullptr) return; Buffer* child = write_head_->next_; if (child == write_head_ || child == read_head_) @@ -413,16 +413,16 @@ void NodeBIO::TryAllocateForWrite(size_t hint) { Buffer* w = write_head_; Buffer* r = read_head_; // If write head is full, next buffer is either read head or not empty. - if (w == NULL || + if (w == nullptr || (w->write_pos_ == w->len_ && (w->next_ == r || w->next_->write_pos_ != 0))) { - size_t len = w == NULL ? initial_ : + size_t len = w == nullptr ? initial_ : kThroughputBufferLength; if (len < hint) len = hint; Buffer* next = new Buffer(len); - if (w == NULL) { + if (w == nullptr) { next->next_ = next; write_head_ = next; read_head_ = next; @@ -435,7 +435,7 @@ void NodeBIO::TryAllocateForWrite(size_t hint) { void NodeBIO::Reset() { - if (read_head_ == NULL) + if (read_head_ == nullptr) return; while (read_head_->read_pos_ != read_head_->write_pos_) { @@ -453,7 +453,7 @@ void NodeBIO::Reset() { NodeBIO::~NodeBIO() { - if (read_head_ == NULL) + if (read_head_ == nullptr) return; Buffer* current = read_head_; @@ -463,8 +463,8 @@ NodeBIO::~NodeBIO() { current = next; } while (current != read_head_); - read_head_ = NULL; - write_head_ = NULL; + read_head_ = nullptr; + write_head_ = nullptr; } } // namespace node diff --git a/src/node_crypto_bio.h b/src/node_crypto_bio.h index 1f5657fbf1..bac79bab0b 100644 --- a/src/node_crypto_bio.h +++ b/src/node_crypto_bio.h @@ -32,8 +32,8 @@ class NodeBIO { public: NodeBIO() : initial_(kInitialBufferLength), length_(0), - read_head_(NULL), - write_head_(NULL) { + read_head_(nullptr), + write_head_(nullptr) { } ~NodeBIO(); @@ -89,7 +89,7 @@ class NodeBIO { } static inline NodeBIO* FromBIO(BIO* bio) { - CHECK_NE(bio->ptr, NULL); + CHECK_NE(bio->ptr, nullptr); return static_cast<NodeBIO*>(bio->ptr); } @@ -113,7 +113,7 @@ class NodeBIO { explicit Buffer(size_t len) : read_pos_(0), write_pos_(0), len_(len), - next_(NULL) { + next_(nullptr) { data_ = new char[len]; } diff --git a/src/node_crypto_clienthello-inl.h b/src/node_crypto_clienthello-inl.h index 6402b4ed4b..53872903af 100644 --- a/src/node_crypto_clienthello-inl.h +++ b/src/node_crypto_clienthello-inl.h @@ -32,11 +32,11 @@ inline void ClientHelloParser::Reset() { body_offset_ = 0; extension_offset_ = 0; session_size_ = 0; - session_id_ = NULL; + session_id_ = nullptr; tls_ticket_size_ = -1; - tls_ticket_ = NULL; + tls_ticket_ = nullptr; servername_size_ = 0; - servername_ = NULL; + servername_ = nullptr; } inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb, @@ -46,7 +46,7 @@ inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb, return; Reset(); - CHECK_NE(onhello_cb, NULL); + CHECK_NE(onhello_cb, nullptr); state_ = kWaiting; onhello_cb_ = onhello_cb; @@ -58,9 +58,9 @@ inline void ClientHelloParser::End() { if (state_ == kEnded) return; state_ = kEnded; - if (onend_cb_ != NULL) { + if (onend_cb_ != nullptr) { onend_cb_(cb_arg_); - onend_cb_ = NULL; + onend_cb_ = nullptr; } } diff --git a/src/node_crypto_clienthello.cc b/src/node_crypto_clienthello.cc index ad0235343c..fd7ed798cb 100644 --- a/src/node_crypto_clienthello.cc +++ b/src/node_crypto_clienthello.cc @@ -123,7 +123,7 @@ void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) { } // Check if we overflowed (do not reply with any private data) - if (session_id_ == NULL || + if (session_id_ == nullptr || session_size_ > 32 || session_id_ + session_size_ > data + avail) { goto fail; @@ -133,7 +133,7 @@ void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) { state_ = kPaused; hello.session_id_ = session_id_; hello.session_size_ = session_size_; - hello.has_ticket_ = tls_ticket_ != NULL && tls_ticket_size_ != 0; + hello.has_ticket_ = tls_ticket_ != nullptr && tls_ticket_size_ != 0; hello.ocsp_request_ = ocsp_request_; hello.servername_ = servername_; hello.servername_size_ = static_cast<uint8_t>(servername_size_); diff --git a/src/node_crypto_clienthello.h b/src/node_crypto_clienthello.h index 3ebcead0c3..33048c2a60 100644 --- a/src/node_crypto_clienthello.h +++ b/src/node_crypto_clienthello.h @@ -25,23 +25,23 @@ #include "node.h" #include <stddef.h> // size_t -#include <stdlib.h> // NULL +#include <stdlib.h> // nullptr namespace node { class ClientHelloParser { public: ClientHelloParser() : state_(kEnded), - onhello_cb_(NULL), - onend_cb_(NULL), - cb_arg_(NULL), + onhello_cb_(nullptr), + onend_cb_(nullptr), + cb_arg_(nullptr), session_size_(0), - session_id_(NULL), + session_id_(nullptr), servername_size_(0), - servername_(NULL), + servername_(nullptr), ocsp_request_(0), tls_ticket_size_(0), - tls_ticket_(NULL) { + tls_ticket_(nullptr) { Reset(); } diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 2d8d32fc53..7fb2312c9a 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -78,7 +78,7 @@ using v8::Value; } \ node::Utf8Value _##member(obj->Get(OneByteString(env->isolate(), \ #member))); \ - if ((*(const char **)valp = *_##member) == NULL) \ + if ((*(const char **)valp = *_##member) == nullptr) \ *(const char **)valp = "<unknown>"; #define SLURP_INT(obj, member, valp) \ @@ -217,7 +217,7 @@ void DTRACE_HTTP_SERVER_REQUEST(const FunctionCallbackInfo<Value>& args) { Local<Value> strfwdfor = headers->Get(env->x_forwarded_string()); node::Utf8Value fwdfor(strfwdfor); - if (!strfwdfor->IsString() || (req.forwardedFor = *fwdfor) == NULL) + if (!strfwdfor->IsString() || (req.forwardedFor = *fwdfor) == nullptr) req.forwardedFor = const_cast<char*>(""); SLURP_CONNECTION(args[1], conn); diff --git a/src/node_dtrace.h b/src/node_dtrace.h index 1169961896..4f61fbd6ad 100644 --- a/src/node_dtrace.h +++ b/src/node_dtrace.h @@ -58,7 +58,7 @@ typedef struct { * * This version of the structure also contains padding that should be zeroed out * by the consumer so that future versions of the translator can simply check if - * a field is present by checking it against NULL. + * a field is present by checking it against nullptr. */ typedef struct { union { diff --git a/src/node_file.cc b/src/node_file.cc index e0bd47d550..86474b75fa 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -70,7 +70,7 @@ class FSReqWrap: public ReqWrap<uv_fs_t> { void* operator new(size_t size) { return new char[size]; } void* operator new(size_t size, char* storage) { return storage; } - FSReqWrap(Environment* env, const char* syscall, char* data = NULL) + FSReqWrap(Environment* env, const char* syscall, char* data = nullptr) : ReqWrap<uv_fs_t>(env, Object::New(env->isolate())), syscall_(syscall), data_(data), @@ -78,10 +78,10 @@ class FSReqWrap: public ReqWrap<uv_fs_t> { } void ReleaseEarly() { - if (data_ == NULL) + if (data_ == nullptr) return; delete[] data_; - data_ = NULL; + data_ = nullptr; } inline const char* syscall() const { return syscall_; } @@ -131,19 +131,19 @@ static void After(uv_fs_t *req) { if (req->result < 0) { // If the request doesn't have a path parameter set. - if (req->path == NULL) { - argv[0] = UVException(req->result, NULL, req_wrap->syscall()); + if (req->path == nullptr) { + argv[0] = UVException(req->result, nullptr, req_wrap->syscall()); } else if ((req->result == UV_EEXIST || req->result == UV_ENOTEMPTY || req->result == UV_EPERM) && req_wrap->dest_len() > 0) { argv[0] = UVException(req->result, - NULL, + nullptr, req_wrap->syscall(), req_wrap->dest()); } else { argv[0] = UVException(req->result, - NULL, + nullptr, req_wrap->syscall(), static_cast<const char*>(req->path)); } @@ -217,7 +217,7 @@ static void After(uv_fs_t *req) { break; if (r != 0) { argv[0] = UVException(r, - NULL, + nullptr, req_wrap->syscall(), static_cast<const char*>(req->path)); break; @@ -259,11 +259,11 @@ struct fs_req_wrap { Environment* env = Environment::GetCurrent(args); \ FSReqWrap* req_wrap; \ char* dest_str = (dest_path); \ - int dest_len = dest_str == NULL ? 0 : strlen(dest_str); \ + int dest_len = dest_str == nullptr ? 0 : strlen(dest_str); \ char* storage = new char[sizeof(*req_wrap) + dest_len]; \ req_wrap = new(storage) FSReqWrap(env, #func); \ req_wrap->dest_len(dest_len); \ - if (dest_str != NULL) { \ + if (dest_str != nullptr) { \ memcpy(const_cast<char*>(req_wrap->dest()), \ dest_str, \ dest_len + 1); \ @@ -277,22 +277,22 @@ struct fs_req_wrap { if (err < 0) { \ uv_fs_t* req = &req_wrap->req_; \ req->result = err; \ - req->path = NULL; \ + req->path = nullptr; \ After(req); \ } \ args.GetReturnValue().Set(req_wrap->persistent()); #define ASYNC_CALL(func, callback, ...) \ - ASYNC_DEST_CALL(func, callback, NULL, __VA_ARGS__) \ + ASYNC_DEST_CALL(func, callback, nullptr, __VA_ARGS__) \ #define SYNC_DEST_CALL(func, path, dest, ...) \ fs_req_wrap req_wrap; \ int err = uv_fs_ ## func(env->event_loop(), \ &req_wrap.req, \ __VA_ARGS__, \ - NULL); \ + nullptr); \ if (err < 0) { \ - if (dest != NULL && \ + if (dest != nullptr && \ (err == UV_EEXIST || \ err == UV_ENOTEMPTY || \ err == UV_EPERM)) { \ @@ -303,7 +303,7 @@ struct fs_req_wrap { } \ #define SYNC_CALL(func, path, ...) \ - SYNC_DEST_CALL(func, path, NULL, __VA_ARGS__) \ + SYNC_DEST_CALL(func, path, nullptr, __VA_ARGS__) \ #define SYNC_REQ req_wrap.req @@ -792,7 +792,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) { return; } - SYNC_CALL(write, NULL, fd, &uvbuf, 1, pos) + SYNC_CALL(write, nullptr, fd, &uvbuf, 1, pos) args.GetReturnValue().Set(SYNC_RESULT); } @@ -814,7 +814,7 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) { Local<Value> cb; Local<Value> string = args[1]; int fd = args[0]->Int32Value(); - char* buf = NULL; + char* buf = nullptr; int64_t pos; size_t len; bool must_free = false; @@ -838,13 +838,13 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) { uv_buf_t uvbuf = uv_buf_init(const_cast<char*>(buf), len); if (!cb->IsFunction()) { - SYNC_CALL(write, NULL, fd, &uvbuf, 1, pos) + SYNC_CALL(write, nullptr, fd, &uvbuf, 1, pos) if (must_free) delete[] buf; return args.GetReturnValue().Set(SYNC_RESULT); } - FSReqWrap* req_wrap = new FSReqWrap(env, "write", must_free ? buf : NULL); + FSReqWrap* req_wrap = new FSReqWrap(env, "write", must_free ? buf : nullptr); int err = uv_fs_write(env->event_loop(), &req_wrap->req_, fd, @@ -857,7 +857,7 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) { if (err < 0) { uv_fs_t* req = &req_wrap->req_; req->result = err; - req->path = NULL; + req->path = nullptr; After(req); } @@ -891,7 +891,7 @@ static void Read(const FunctionCallbackInfo<Value>& args) { size_t len; int64_t pos; - char * buf = NULL; + char * buf = nullptr; if (!Buffer::HasInstance(args[1])) { return env->ThrowError("Second argument needs to be a buffer"); diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index eb89829547..233d903268 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -123,13 +123,13 @@ struct StringPtr { on_heap_ = false; } - str_ = NULL; + str_ = nullptr; size_ = 0; } void Update(const char* str, size_t size) { - if (str_ == NULL) + if (str_ == nullptr) str_ = str; else if (on_heap_ || str_ + size_ != str) { // Non-consecutive input, make a copy on the heap. @@ -168,7 +168,7 @@ class Parser : public BaseObject { Parser(Environment* env, Local<Object> wrap, enum http_parser_type type) : BaseObject(env, wrap), current_buffer_len_(0), - current_buffer_data_(NULL) { + current_buffer_data_(nullptr) { Wrap(object(), this); Init(type); } @@ -338,7 +338,7 @@ class Parser : public BaseObject { if (!cb->IsFunction()) return 0; - Local<Value> r = cb.As<Function>()->Call(obj, 0, NULL); + Local<Value> r = cb.As<Function>()->Call(obj, 0, nullptr); if (r.IsEmpty()) { got_exception_ = true; @@ -385,7 +385,7 @@ class Parser : public BaseObject { Parser* parser = Unwrap<Parser>(args.Holder()); CHECK(parser->current_buffer_.IsEmpty()); CHECK_EQ(parser->current_buffer_len_, 0); - CHECK_EQ(parser->current_buffer_data_, NULL); + CHECK_EQ(parser->current_buffer_data_, nullptr); CHECK_EQ(Buffer::HasInstance(args[0]), true); Local<Object> buffer_obj = args[0].As<Object>(); @@ -408,7 +408,7 @@ class Parser : public BaseObject { // Unassign the 'buffer_' variable parser->current_buffer_.Clear(); parser->current_buffer_len_ = 0; - parser->current_buffer_data_ = NULL; + parser->current_buffer_data_ = nullptr; // If there was an exception in one of the callbacks if (parser->got_exception_) @@ -441,7 +441,7 @@ class Parser : public BaseObject { CHECK(parser->current_buffer_.IsEmpty()); parser->got_exception_ = false; - int rv = http_parser_execute(&(parser->parser_), &settings, NULL, 0); + int rv = http_parser_execute(&(parser->parser_), &settings, nullptr, 0); if (parser->got_exception_) return; diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 6d6144dc78..d4f8b30bae 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -67,7 +67,7 @@ namespace node { namespace i18n { bool InitializeICUDirectory(const char* icu_data_path) { - if (icu_data_path != NULL) { + if (icu_data_path != nullptr) { u_setDataDirectory(icu_data_path); return true; // no error } else { diff --git a/src/node_internals.h b/src/node_internals.h index 2caa81ce18..01081f1d1d 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -51,28 +51,28 @@ v8::Handle<v8::Value> MakeCallback(Environment* env, v8::Handle<v8::Object> recv, const char* method, int argc = 0, - v8::Handle<v8::Value>* argv = NULL); + v8::Handle<v8::Value>* argv = nullptr); // Call with valid HandleScope and while inside Context scope. v8::Handle<v8::Value> MakeCallback(Environment* env, v8::Handle<v8::Object> recv, uint32_t index, int argc = 0, - v8::Handle<v8::Value>* argv = NULL); + v8::Handle<v8::Value>* argv = nullptr); // Call with valid HandleScope and while inside Context scope. v8::Handle<v8::Value> MakeCallback(Environment* env, v8::Handle<v8::Object> recv, v8::Handle<v8::String> symbol, int argc = 0, - v8::Handle<v8::Value>* argv = NULL); + v8::Handle<v8::Value>* argv = nullptr); // Call with valid HandleScope and while inside Context scope. v8::Handle<v8::Value> MakeCallback(Environment* env, v8::Handle<v8::Value> recv, v8::Handle<v8::Function> callback, int argc = 0, - v8::Handle<v8::Value>* argv = NULL); + v8::Handle<v8::Value>* argv = nullptr); // Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object. // Sets address and port properties on the info object and returns it. @@ -174,14 +174,14 @@ void ThrowTypeError(v8::Isolate* isolate, const char* errmsg); void ThrowRangeError(v8::Isolate* isolate, const char* errmsg); void ThrowErrnoException(v8::Isolate* isolate, int errorno, - const char* syscall = NULL, - const char* message = NULL, - const char* path = NULL); + const char* syscall = nullptr, + const char* message = nullptr, + const char* path = nullptr); void ThrowUVException(v8::Isolate* isolate, int errorno, - const char* syscall = NULL, - const char* message = NULL, - const char* path = NULL); + const char* syscall = nullptr, + const char* message = nullptr, + const char* path = nullptr); NODE_DEPRECATED("Use ThrowError(isolate)", inline void ThrowError(const char* errmsg) { @@ -200,17 +200,17 @@ NODE_DEPRECATED("Use ThrowRangeError(isolate)", }) NODE_DEPRECATED("Use ThrowErrnoException(isolate)", inline void ThrowErrnoException(int errorno, - const char* syscall = NULL, - const char* message = NULL, - const char* path = NULL) { + const char* syscall = nullptr, + const char* message = nullptr, + const char* path = nullptr) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); return ThrowErrnoException(isolate, errorno, syscall, message, path); }) NODE_DEPRECATED("Use ThrowUVException(isolate)", inline void ThrowUVException(int errorno, - const char* syscall = NULL, - const char* message = NULL, - const char* path = NULL) { + const char* syscall = nullptr, + const char* message = nullptr, + const char* path = nullptr) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); return ThrowUVException(isolate, errorno, syscall, message, path); }) @@ -223,7 +223,7 @@ inline void NODE_SET_EXTERNAL(v8::Handle<v8::ObjectTemplate> target, v8::Local<v8::String> prop = v8::String::NewFromUtf8(isolate, key); target->SetAccessor(prop, getter, - NULL, + nullptr, v8::Handle<v8::Value>(), v8::DEFAULT, static_cast<v8::PropertyAttribute>(v8::ReadOnly | diff --git a/src/node_main.cc b/src/node_main.cc index 6471551d2c..28ce29fa97 100644 --- a/src/node_main.cc +++ b/src/node_main.cc @@ -31,10 +31,10 @@ int wmain(int argc, wchar_t *wargv[]) { 0, wargv[i], -1, - NULL, + nullptr, 0, - NULL, - NULL); + nullptr, + nullptr); if (size == 0) { // This should never happen. fprintf(stderr, "Could not convert arguments to utf8."); @@ -48,8 +48,8 @@ int wmain(int argc, wchar_t *wargv[]) { -1, argv[i], size, - NULL, - NULL); + nullptr, + nullptr); if (result == 0) { // This should never happen. fprintf(stderr, "Could not convert arguments to utf8."); diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index 8f82bc357e..43112933fe 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -122,7 +122,7 @@ void StatWatcher::Stop(const FunctionCallbackInfo<Value>& args) { StatWatcher* wrap = Unwrap<StatWatcher>(args.Holder()); Environment* env = wrap->env(); Context::Scope context_scope(env->context()); - wrap->MakeCallback(env->onstop_string(), 0, NULL); + wrap->MakeCallback(env->onstop_string(), 0, nullptr); wrap->Stop(); } diff --git a/src/node_v8_platform.cc b/src/node_v8_platform.cc index 566fd798db..20c79ab417 100644 --- a/src/node_v8_platform.cc +++ b/src/node_v8_platform.cc @@ -124,7 +124,7 @@ TaskQueue::~TaskQueue() { CHECK_EQ(read_off_, write_off_); delete[] ring_; - ring_ = NULL; + ring_ = nullptr; uv_sem_destroy(&sem_); uv_cond_destroy(&cond_); uv_mutex_destroy(&mutex_); @@ -135,7 +135,7 @@ void TaskQueue::Push(Task* task) { uv_mutex_lock(&mutex_); // Wait for empty cell - while (ring_[write_off_] != NULL) + while (ring_[write_off_] != nullptr) uv_cond_wait(&cond_, &mutex_); ring_[write_off_] = task; @@ -152,7 +152,7 @@ Task* TaskQueue::Shift() { uv_mutex_lock(&mutex_); Task* task = ring_[read_off_]; - ring_[read_off_] = NULL; + ring_[read_off_] = nullptr; uv_cond_signal(&cond_); read_off_++; diff --git a/src/node_watchdog.cc b/src/node_watchdog.cc index 65e7b27234..147cc10b9e 100644 --- a/src/node_watchdog.cc +++ b/src/node_watchdog.cc @@ -69,7 +69,7 @@ void Watchdog::Destroy() { uv_async_send(&async_); uv_thread_join(&thread_); - uv_close(reinterpret_cast<uv_handle_t*>(&async_), NULL); + uv_close(reinterpret_cast<uv_handle_t*>(&async_), nullptr); // UV_RUN_DEFAULT so that libuv has a chance to clean up. uv_run(loop_, UV_RUN_DEFAULT); @@ -77,7 +77,7 @@ void Watchdog::Destroy() { int rc = uv_loop_close(loop_); CHECK_EQ(0, rc); delete loop_; - loop_ = NULL; + loop_ = nullptr; destroyed_ = true; } @@ -91,7 +91,7 @@ void Watchdog::Run(void* arg) { // Loop ref count reaches zero when both handles are closed. // Close the timer handle on this side and let Destroy() close async_ - uv_close(reinterpret_cast<uv_handle_t*>(&wd->timer_), NULL); + uv_close(reinterpret_cast<uv_handle_t*>(&wd->timer_), nullptr); } diff --git a/src/node_win32_etw_provider-inl.h b/src/node_win32_etw_provider-inl.h index 0bc2170767..1934712361 100644 --- a/src/node_win32_etw_provider-inl.h +++ b/src/node_win32_etw_provider-inl.h @@ -227,8 +227,8 @@ void NODE_V8SYMBOL_ADD(LPCSTR symbol, int len) { if (events_enabled > 0) { wchar_t symbuf[128]; - if (symbol == NULL) { - SETSYMBUF(L"NULL"); + if (symbol == nullptr) { + SETSYMBUF(L"nullptr"); } else { symbol_len = MultiByteToWideChar(CP_ACP, 0, @@ -245,7 +245,7 @@ void NODE_V8SYMBOL_ADD(LPCSTR symbol, symbuf[symbol_len] = L'\0'; } } - void* context = NULL; + void* context = nullptr; INT64 size = (INT64)len; INT_PTR id = (INT_PTR)addr1; INT16 flags = 0; diff --git a/src/node_win32_etw_provider.cc b/src/node_win32_etw_provider.cc index c228dd884c..1941b5a566 100644 --- a/src/node_win32_etw_provider.cc +++ b/src/node_win32_etw_provider.cc @@ -133,7 +133,7 @@ void etw_events_change_async(uv_async_t* handle) { } else { v8::Isolate::GetCurrent()->SetJitCodeEventHandler( v8::kJitCodeEventDefault, - NULL); + nullptr); } } @@ -184,7 +184,7 @@ void init_etw() { if (event_register) { DWORD status = event_register(&NODE_ETW_PROVIDER, etw_events_enable_callback, - NULL, + nullptr, &node_provider); CHECK_EQ(status, ERROR_SUCCESS); } @@ -201,11 +201,11 @@ void shutdown_etw() { events_enabled = 0; v8::Isolate::GetCurrent()->SetJitCodeEventHandler( v8::kJitCodeEventDefault, - NULL); + nullptr); if (advapi) { FreeLibrary(advapi); - advapi = NULL; + advapi = nullptr; } } } diff --git a/src/node_win32_perfctr_provider.cc b/src/node_win32_perfctr_provider.cc index 9258104947..bfe28e74f6 100644 --- a/src/node_win32_perfctr_provider.cc +++ b/src/node_win32_perfctr_provider.cc @@ -119,7 +119,7 @@ PPERF_COUNTERSET_INSTANCE perfctr_instance; namespace node { -EXTERN_C DECLSPEC_SELECTANY HANDLE NodeCounterProvider = NULL; +EXTERN_C DECLSPEC_SELECTANY HANDLE NodeCounterProvider = nullptr; void InitPerfCountersWin32() { ULONG status; @@ -166,7 +166,7 @@ void InitPerfCountersWin32() { if (!perfctr_startProvider || !perfctr_setCounterSetInfo || !perfctr_createInstance) { - NodeCounterProvider = NULL; + NodeCounterProvider = nullptr; return; } @@ -174,7 +174,7 @@ void InitPerfCountersWin32() { &providerContext, &NodeCounterProvider); if (status != ERROR_SUCCESS) { - NodeCounterProvider = NULL; + NodeCounterProvider = nullptr; return; } @@ -183,7 +183,7 @@ void InitPerfCountersWin32() { sizeof(NodeCounterSetInfo)); if (status != ERROR_SUCCESS) { perfctr_stopProvider(NodeCounterProvider); - NodeCounterProvider = NULL; + NodeCounterProvider = nullptr; return; } @@ -191,30 +191,30 @@ void InitPerfCountersWin32() { &NodeCounterSetGuid, Inst, 1); - if (perfctr_instance == NULL) { + if (perfctr_instance == nullptr) { perfctr_stopProvider(NodeCounterProvider); - NodeCounterProvider = NULL; + NodeCounterProvider = nullptr; } } } void TermPerfCountersWin32() { - if (NodeCounterProvider != NULL && - perfctr_stopProvider != NULL) { + if (NodeCounterProvider != nullptr && + perfctr_stopProvider != nullptr) { perfctr_stopProvider(NodeCounterProvider); - NodeCounterProvider = NULL; + NodeCounterProvider = nullptr; } if (advapimod) { FreeLibrary(advapimod); - advapimod = NULL; + advapimod = nullptr; } } void NODE_COUNT_HTTP_SERVER_REQUEST() { - if (NodeCounterProvider != NULL && perfctr_incrementULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongValue != nullptr) { perfctr_incrementULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_HTTP_SERVER_REQUEST, @@ -224,7 +224,7 @@ void NODE_COUNT_HTTP_SERVER_REQUEST() { void NODE_COUNT_HTTP_SERVER_RESPONSE() { - if (NodeCounterProvider != NULL && perfctr_incrementULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongValue != nullptr) { perfctr_incrementULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_HTTP_SERVER_RESPONSE, @@ -234,7 +234,7 @@ void NODE_COUNT_HTTP_SERVER_RESPONSE() { void NODE_COUNT_HTTP_CLIENT_REQUEST() { - if (NodeCounterProvider != NULL && perfctr_incrementULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongValue != nullptr) { perfctr_incrementULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_HTTP_CLIENT_REQUEST, @@ -244,7 +244,7 @@ void NODE_COUNT_HTTP_CLIENT_REQUEST() { void NODE_COUNT_HTTP_CLIENT_RESPONSE() { - if (NodeCounterProvider != NULL && perfctr_incrementULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongValue != nullptr) { perfctr_incrementULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_HTTP_CLIENT_RESPONSE, @@ -254,7 +254,7 @@ void NODE_COUNT_HTTP_CLIENT_RESPONSE() { void NODE_COUNT_SERVER_CONN_OPEN() { - if (NodeCounterProvider != NULL && perfctr_incrementULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongValue != nullptr) { perfctr_incrementULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_SERVER_CONNS, @@ -264,7 +264,7 @@ void NODE_COUNT_SERVER_CONN_OPEN() { void NODE_COUNT_SERVER_CONN_CLOSE() { - if (NodeCounterProvider != NULL && perfctr_decrementULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_decrementULongValue != nullptr) { perfctr_decrementULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_SERVER_CONNS, @@ -274,7 +274,7 @@ void NODE_COUNT_SERVER_CONN_CLOSE() { void NODE_COUNT_NET_BYTES_SENT(int bytes) { - if (NodeCounterProvider != NULL && perfctr_incrementULongLongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongLongValue != nullptr) { perfctr_incrementULongLongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_NET_BYTES_SENT, @@ -284,7 +284,7 @@ void NODE_COUNT_NET_BYTES_SENT(int bytes) { void NODE_COUNT_NET_BYTES_RECV(int bytes) { - if (NodeCounterProvider != NULL && perfctr_incrementULongLongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongLongValue != nullptr) { perfctr_incrementULongLongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_NET_BYTES_RECV, @@ -304,7 +304,7 @@ uint64_t NODE_COUNT_GET_GC_RAWTIME() { void NODE_COUNT_GC_PERCENTTIME(unsigned int percent) { - if (NodeCounterProvider != NULL && perfctr_setULongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_setULongValue != nullptr) { perfctr_setULongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_GC_PERCENTTIME, @@ -314,7 +314,7 @@ void NODE_COUNT_GC_PERCENTTIME(unsigned int percent) { void NODE_COUNT_PIPE_BYTES_SENT(int bytes) { - if (NodeCounterProvider != NULL && perfctr_incrementULongLongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongLongValue != nullptr) { perfctr_incrementULongLongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_PIPE_BYTES_SENT, @@ -324,7 +324,7 @@ void NODE_COUNT_PIPE_BYTES_SENT(int bytes) { void NODE_COUNT_PIPE_BYTES_RECV(int bytes) { - if (NodeCounterProvider != NULL && perfctr_incrementULongLongValue != NULL) { + if (NodeCounterProvider != nullptr && perfctr_incrementULongLongValue != nullptr) { perfctr_incrementULongLongValue(NodeCounterProvider, perfctr_instance, NODE_COUNTER_PIPE_BYTES_RECV, diff --git a/src/node_win32_perfctr_provider.h b/src/node_win32_perfctr_provider.h index d62fb92ced..6e6c4048b6 100644 --- a/src/node_win32_perfctr_provider.h +++ b/src/node_win32_perfctr_provider.h @@ -32,7 +32,7 @@ namespace node { extern HANDLE NodeCounterProvider; -INLINE bool NODE_COUNTER_ENABLED() { return NodeCounterProvider != NULL; } +INLINE bool NODE_COUNTER_ENABLED() { return NodeCounterProvider != nullptr; } void NODE_COUNT_HTTP_SERVER_REQUEST(); void NODE_COUNT_HTTP_SERVER_RESPONSE(); void NODE_COUNT_HTTP_CLIENT_REQUEST(); diff --git a/src/node_wrap.h b/src/node_wrap.h index 8762ec40c7..5403f711fe 100644 --- a/src/node_wrap.h +++ b/src/node_wrap.h @@ -60,7 +60,7 @@ inline uv_stream_t* HandleToStream(Environment* env, return reinterpret_cast<uv_stream_t*>(wrap->UVHandle()); }); - return NULL; + return nullptr; } } // namespace node diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 22e62d9fb9..9ad0ad9886 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -76,7 +76,7 @@ class ZCtx : public AsyncWrap { ZCtx(Environment* env, Local<Object> wrap, node_zlib_mode mode) : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_ZLIB), chunk_size_(0), - dictionary_(NULL), + dictionary_(nullptr), dictionary_len_(0), err_(0), flush_(0), @@ -120,9 +120,9 @@ class ZCtx : public AsyncWrap { } mode_ = NONE; - if (dictionary_ != NULL) { + if (dictionary_ != nullptr) { delete[] dictionary_; - dictionary_ = NULL; + dictionary_ = nullptr; } } @@ -259,7 +259,7 @@ class ZCtx : public AsyncWrap { ctx->err_ = inflate(&ctx->strm_, ctx->flush_); // If data was encoded with dictionary - if (ctx->err_ == Z_NEED_DICT && ctx->dictionary_ != NULL) { + if (ctx->err_ == Z_NEED_DICT && ctx->dictionary_ != nullptr) { // Load it ctx->err_ = inflateSetDictionary(&ctx->strm_, ctx->dictionary_, @@ -296,7 +296,7 @@ class ZCtx : public AsyncWrap { // normal statuses, not fatal break; case Z_NEED_DICT: - if (ctx->dictionary_ == NULL) + if (ctx->dictionary_ == nullptr) ZCtx::Error(ctx, "Missing dictionary"); else ZCtx::Error(ctx, "Bad dictionary"); @@ -346,7 +346,7 @@ class ZCtx : public AsyncWrap { // If you hit this assertion, you forgot to enter the v8::Context first. CHECK_EQ(env->context(), env->isolate()->GetCurrentContext()); - if (ctx->strm_.msg != NULL) { + if (ctx->strm_.msg != nullptr) { message = ctx->strm_.msg; } @@ -402,7 +402,7 @@ class ZCtx : public AsyncWrap { strategy == Z_FIXED || strategy == Z_DEFAULT_STRATEGY) && "invalid strategy"); - char* dictionary = NULL; + char* dictionary = nullptr; size_t dictionary_len = 0; if (args.Length() >= 5 && Buffer::HasInstance(args[4])) { Local<Object> dictionary_ = args[4]->ToObject(); @@ -495,7 +495,7 @@ class ZCtx : public AsyncWrap { } static void SetDictionary(ZCtx* ctx) { - if (ctx->dictionary_ == NULL) + if (ctx->dictionary_ == nullptr) return; ctx->err_ = Z_OK; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 65f16d64d0..c99114b77a 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -83,7 +83,7 @@ void PipeWrap::Initialize(Handle<Object> target, static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); t->InstanceTemplate()->SetAccessor(env->fd_string(), StreamWrap::GetFD, - NULL, + nullptr, Handle<Value>(), v8::DEFAULT, attributes); diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 69c696acd0..61cb6cff28 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -115,7 +115,7 @@ class ProcessWrap : public HandleWrap { Local<String> handle_key = env->handle_string(); Local<Object> handle = stdio->Get(handle_key).As<Object>(); uv_stream_t* stream = HandleToStream(env, handle); - CHECK_NE(stream, NULL); + CHECK_NE(stream, nullptr); options->stdio[i].flags = UV_INHERIT_STREAM; options->stdio[i].data.stream = stream; @@ -182,13 +182,13 @@ class ProcessWrap : public HandleWrap { if (!argv_v.IsEmpty() && argv_v->IsArray()) { Local<Array> js_argv = Local<Array>::Cast(argv_v); int argc = js_argv->Length(); - // Heap allocate to detect errors. +1 is for NULL. + // Heap allocate to detect errors. +1 is for nullptr. options.args = new char*[argc + 1]; for (int i = 0; i < argc; i++) { node::Utf8Value arg(js_argv->Get(i)); options.args[i] = strdup(*arg); } - options.args[argc] = NULL; + options.args[argc] = nullptr; } // options.cwd @@ -208,7 +208,7 @@ class ProcessWrap : public HandleWrap { node::Utf8Value pair(env->Get(i)); options.env[i] = strdup(*pair); } - options.env[envc] = NULL; + options.env[envc] = nullptr; } // options.stdio @@ -261,7 +261,7 @@ class ProcessWrap : public HandleWrap { int64_t exit_status, int term_signal) { ProcessWrap* wrap = static_cast<ProcessWrap*>(handle->data); - CHECK_NE(wrap, NULL); + CHECK_NE(wrap, nullptr); CHECK_EQ(&wrap->process_, handle); Environment* env = wrap->env(); diff --git a/src/smalloc.cc b/src/smalloc.cc index 9ce5ea4963..517492818f 100644 --- a/src/smalloc.cc +++ b/src/smalloc.cc @@ -135,7 +135,7 @@ void CallbackInfo::WeakCallback(Isolate* isolate, Local<Object> object) { CHECK_GT(array_length * array_size, array_length); // Overflow check. array_length *= array_size; } - object->SetIndexedPropertiesToExternalArrayData(NULL, array_type, 0); + object->SetIndexedPropertiesToExternalArrayData(nullptr, array_type, 0); int64_t change_in_bytes = -static_cast<int64_t>(array_length + sizeof(*this)); isolate->AdjustAmountOfExternalAllocatedMemory(change_in_bytes); callback_(static_cast<char*>(array_data), hint_); @@ -271,7 +271,7 @@ void SliceOnto(const FunctionCallbackInfo<Value>& args) { length *= source_size; } - CHECK(source_data != NULL || length == 0); + CHECK(source_data != nullptr || length == 0); CHECK_LE(end, source_len); CHECK_LE(start, end); @@ -321,10 +321,10 @@ void Alloc(Environment* env, CHECK_GT(type_size, 0); if (length == 0) - return Alloc(env, obj, NULL, length, type); + return Alloc(env, obj, nullptr, length, type); char* data = static_cast<char*>(malloc(length)); - if (data == NULL) { + if (data == nullptr) { FatalError("node::smalloc::Alloc(v8::Handle<v8::Object>, size_t," " v8::ExternalArrayType)", "Out Of Memory"); } @@ -377,8 +377,8 @@ void AllocDispose(Environment* env, Handle<Object> obj) { length *= array_size; - if (data != NULL) { - obj->SetIndexedPropertiesToExternalArrayData(NULL, + if (data != nullptr) { + obj->SetIndexedPropertiesToExternalArrayData(nullptr, kExternalUint8Array, 0); free(data); diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 3cd33ef466..647ce85020 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -48,14 +48,14 @@ using v8::Value; SyncProcessOutputBuffer::SyncProcessOutputBuffer() : used_(0), - next_(NULL) { + next_(nullptr) { } void SyncProcessOutputBuffer::OnAlloc(size_t suggested_size, uv_buf_t* buf) const { if (used() == kBufferSize) - *buf = uv_buf_init(NULL, 0); + *buf = uv_buf_init(nullptr, 0); else *buf = uv_buf_init(data_ + used(), available()); } @@ -103,8 +103,8 @@ SyncProcessStdioPipe::SyncProcessStdioPipe(SyncProcessRunner* process_handler, writable_(writable), input_buffer_(input_buffer), - first_output_buffer_(NULL), - last_output_buffer_(NULL), + first_output_buffer_(nullptr), + last_output_buffer_(nullptr), uv_pipe_(), write_req_(), @@ -121,7 +121,7 @@ SyncProcessStdioPipe::~SyncProcessStdioPipe() { SyncProcessOutputBuffer* buf; SyncProcessOutputBuffer* next; - for (buf = first_output_buffer_; buf != NULL; buf = next) { + for (buf = first_output_buffer_; buf != nullptr; buf = next) { next = buf->next(); delete buf; } @@ -151,7 +151,7 @@ int SyncProcessStdioPipe::Start() { if (readable()) { if (input_buffer_.len > 0) { - CHECK_NE(input_buffer_.base, NULL); + CHECK_NE(input_buffer_.base, nullptr); int r = uv_write(&write_req_, uv_stream(), @@ -237,7 +237,7 @@ size_t SyncProcessStdioPipe::OutputLength() const { SyncProcessOutputBuffer* buf; size_t size = 0; - for (buf = first_output_buffer_; buf != NULL; buf = buf->next()) + for (buf = first_output_buffer_; buf != nullptr; buf = buf->next()) size += buf->used(); return size; @@ -248,7 +248,7 @@ void SyncProcessStdioPipe::CopyOutput(char* dest) const { SyncProcessOutputBuffer* buf; size_t offset = 0; - for (buf = first_output_buffer_; buf != NULL; buf = buf->next()) + for (buf = first_output_buffer_; buf != nullptr; buf = buf->next()) offset += buf->Copy(dest + offset); } @@ -259,7 +259,7 @@ void SyncProcessStdioPipe::OnAlloc(size_t suggested_size, uv_buf_t* buf) { // SyncProcessOutputBuffer::OnRead that would fail if this assumption was // ever violated. - if (last_output_buffer_ == NULL) { + if (last_output_buffer_ == nullptr) { // Allocate the first capture buffer. first_output_buffer_ = new SyncProcessOutputBuffer(); last_output_buffer_ = first_output_buffer_; @@ -373,18 +373,18 @@ SyncProcessRunner::SyncProcessRunner(Environment* env) timeout_(0), kill_signal_(SIGTERM), - uv_loop_(NULL), + uv_loop_(nullptr), stdio_count_(0), - uv_stdio_containers_(NULL), - stdio_pipes_(NULL), + uv_stdio_containers_(nullptr), + stdio_pipes_(nullptr), stdio_pipes_initialized_(false), uv_process_options_(), - file_buffer_(NULL), - args_buffer_(NULL), - env_buffer_(NULL), - cwd_buffer_(NULL), + file_buffer_(nullptr), + args_buffer_(nullptr), + env_buffer_(nullptr), + cwd_buffer_(nullptr), uv_process_(), killed_(false), @@ -408,9 +408,9 @@ SyncProcessRunner::SyncProcessRunner(Environment* env) SyncProcessRunner::~SyncProcessRunner() { CHECK_EQ(lifecycle_, kHandlesClosed); - if (stdio_pipes_ != NULL) { + if (stdio_pipes_ != nullptr) { for (size_t i = 0; i < stdio_count_; i++) { - if (stdio_pipes_[i] != NULL) + if (stdio_pipes_[i] != nullptr) delete stdio_pipes_[i]; } } @@ -452,7 +452,7 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) { lifecycle_ = kInitialized; uv_loop_ = new uv_loop_t; - if (uv_loop_ == NULL) + if (uv_loop_ == nullptr) return SetError(UV_ENOMEM); CHECK_EQ(uv_loop_init(uv_loop_), 0); @@ -487,7 +487,7 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) { for (uint32_t i = 0; i < stdio_count_; i++) { SyncProcessStdioPipe* h = stdio_pipes_[i]; - if (h != NULL) { + if (h != nullptr) { r = h->Start(); if (r < 0) return SetPipeError(r); @@ -507,14 +507,14 @@ void SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) { void SyncProcessRunner::CloseHandlesAndDeleteLoop() { CHECK_LT(lifecycle_, kHandlesClosed); - if (uv_loop_ != NULL) { + if (uv_loop_ != nullptr) { CloseStdioPipes(); CloseKillTimer(); // Close the process handle when ExitCallback was not called. uv_handle_t* uv_process_handle = reinterpret_cast<uv_handle_t*>(&uv_process_); if (!uv_is_closing(uv_process_handle)) - uv_close(uv_process_handle, NULL); + uv_close(uv_process_handle, nullptr); // Give closing watchers a chance to finish closing and get their close // callbacks called. @@ -524,7 +524,7 @@ void SyncProcessRunner::CloseHandlesAndDeleteLoop() { CHECK_EQ(uv_loop_close(uv_loop_), 0); delete uv_loop_; - uv_loop_ = NULL; + uv_loop_ = nullptr; } else { // If the loop doesn't exist, neither should any pipes or timers. @@ -540,11 +540,11 @@ void SyncProcessRunner::CloseStdioPipes() { CHECK_LT(lifecycle_, kHandlesClosed); if (stdio_pipes_initialized_) { - CHECK_NE(stdio_pipes_, NULL); - CHECK_NE(uv_loop_, NULL); + CHECK_NE(stdio_pipes_, nullptr); + CHECK_NE(uv_loop_, nullptr); for (uint32_t i = 0; i < stdio_count_; i++) { - if (stdio_pipes_[i] != NULL) + if (stdio_pipes_[i] != nullptr) stdio_pipes_[i]->Close(); } @@ -558,7 +558,7 @@ void SyncProcessRunner::CloseKillTimer() { if (kill_timer_initialized_) { CHECK_GT(timeout_, 0); - CHECK_NE(uv_loop_, NULL); + CHECK_NE(uv_loop_, nullptr); uv_handle_t* uv_timer_handle = reinterpret_cast<uv_handle_t*>(&uv_timer_); uv_ref(uv_timer_handle); @@ -684,14 +684,14 @@ Local<Object> SyncProcessRunner::BuildResultObject() { Local<Array> SyncProcessRunner::BuildOutputArray() { CHECK_GE(lifecycle_, kInitialized); - CHECK_NE(stdio_pipes_, NULL); + CHECK_NE(stdio_pipes_, nullptr); EscapableHandleScope scope(env()->isolate()); Local<Array> js_output = Array::New(env()->isolate(), stdio_count_); for (uint32_t i = 0; i < stdio_count_; i++) { SyncProcessStdioPipe* h = stdio_pipes_[i]; - if (h != NULL && h->writable()) + if (h != nullptr && h->writable()) js_output->Set(i, h->GetOutputAsBuffer()); else js_output->Set(i, Null(env()->isolate())); @@ -845,7 +845,7 @@ int SyncProcessRunner::ParseStdioOption(int child_fd, bool readable = js_stdio_option->Get(rs)->BooleanValue(); bool writable = js_stdio_option->Get(ws)->BooleanValue(); - uv_buf_t buf = uv_buf_init(NULL, 0); + uv_buf_t buf = uv_buf_init(nullptr, 0); if (readable) { Local<Value> input = js_stdio_option->Get(env()->input_string()); @@ -876,7 +876,7 @@ int SyncProcessRunner::ParseStdioOption(int child_fd, int SyncProcessRunner::AddStdioIgnore(uint32_t child_fd) { CHECK_LT(child_fd, stdio_count_); - CHECK_EQ(stdio_pipes_[child_fd], NULL); + CHECK_EQ(stdio_pipes_[child_fd], nullptr); uv_stdio_containers_[child_fd].flags = UV_IGNORE; @@ -889,7 +889,7 @@ int SyncProcessRunner::AddStdioPipe(uint32_t child_fd, bool writable, uv_buf_t input_buffer) { CHECK_LT(child_fd, stdio_count_); - CHECK_EQ(stdio_pipes_[child_fd], NULL); + CHECK_EQ(stdio_pipes_[child_fd], nullptr); SyncProcessStdioPipe* h = new SyncProcessStdioPipe(this, readable, @@ -913,7 +913,7 @@ int SyncProcessRunner::AddStdioPipe(uint32_t child_fd, int SyncProcessRunner::AddStdioInheritFD(uint32_t child_fd, int inherit_fd) { CHECK_LT(child_fd, stdio_count_); - CHECK_EQ(stdio_pipes_[child_fd], NULL); + CHECK_EQ(stdio_pipes_[child_fd], nullptr); uv_stdio_containers_[child_fd].flags = UV_INHERIT_FD; uv_stdio_containers_[child_fd].data.fd = inherit_fd; @@ -1024,7 +1024,7 @@ int SyncProcessRunner::CopyJsStringArray(Local<Value> js_value, sizeof(void*)); // NOLINT(runtime/sizeof) } - list[length] = NULL; + list[length] = nullptr; *target = buffer; return 0; @@ -1035,7 +1035,7 @@ void SyncProcessRunner::ExitCallback(uv_process_t* handle, int64_t exit_status, int term_signal) { SyncProcessRunner* self = reinterpret_cast<SyncProcessRunner*>(handle->data); - uv_close(reinterpret_cast<uv_handle_t*>(handle), NULL); + uv_close(reinterpret_cast<uv_handle_t*>(handle), nullptr); self->OnExit(exit_status, term_signal); } diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 805f7a3f02..a6c64ac8bd 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -73,7 +73,7 @@ void StreamWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) { HandleScope scope(args.GetIsolate()); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); int fd = -1; - if (wrap != NULL && wrap->stream() != NULL) { + if (wrap != nullptr && wrap->stream() != nullptr) { fd = wrap->stream()->io_watcher.fd; } args.GetReturnValue().Set(fd); @@ -214,7 +214,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) { err = wrap->callbacks()->DoWrite(req_wrap, bufs, count, - NULL, + nullptr, StreamWrap::AfterWrite); req_wrap->Dispatched(); req_wrap_obj->Set(env->async(), True(env->isolate())); @@ -226,7 +226,7 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) { done: const char* msg = wrap->callbacks()->Error(); - if (msg != NULL) + if (msg != nullptr) req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg)); req_wrap_obj->Set(env->bytes_string(), Integer::NewFromUnsigned(env->isolate(), length)); @@ -322,10 +322,10 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) { err = wrap->callbacks()->DoWrite(req_wrap, &buf, 1, - NULL, + nullptr, StreamWrap::AfterWrite); } else { - uv_handle_t* send_handle = NULL; + uv_handle_t* send_handle = nullptr; if (args[2]->IsObject()) { Local<Object> send_handle_obj = args[2].As<Object>(); @@ -355,7 +355,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) { done: const char* msg = wrap->callbacks()->Error(); - if (msg != NULL) + if (msg != nullptr) req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg)); req_wrap_obj->Set(env->bytes_string(), Integer::NewFromUnsigned(env->isolate(), data_size)); @@ -449,7 +449,7 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) { int err = wrap->callbacks()->DoWrite(req_wrap, bufs, count, - NULL, + nullptr, StreamWrap::AfterWrite); // Deallocate space @@ -461,7 +461,7 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) { req_wrap->object()->Set(env->bytes_string(), Number::New(env->isolate(), bytes)); const char* msg = wrap->callbacks()->Error(); - if (msg != NULL) + if (msg != nullptr) req_wrap_obj->Set(env->error_string(), OneByteString(env->isolate(), msg)); if (err) { @@ -523,7 +523,7 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) { }; const char* msg = wrap->callbacks()->Error(); - if (msg != NULL) + if (msg != nullptr) argv[3] = OneByteString(env->isolate(), msg); req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); @@ -578,7 +578,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { const char* StreamWrapCallbacks::Error() { - return NULL; + return nullptr; } @@ -628,7 +628,7 @@ int StreamWrapCallbacks::DoWrite(WriteWrap* w, uv_stream_t* send_handle, uv_write_cb cb) { int r; - if (send_handle == NULL) { + if (send_handle == nullptr) { r = uv_write(&w->req_, wrap()->stream(), bufs, count, cb); } else { r = uv_write2(&w->req_, wrap()->stream(), bufs, count, send_handle, cb); @@ -662,7 +662,7 @@ void StreamWrapCallbacks::DoAlloc(uv_handle_t* handle, buf->base = static_cast<char*>(malloc(suggested_size)); buf->len = suggested_size; - if (buf->base == NULL && suggested_size > 0) { + if (buf->base == nullptr && suggested_size > 0) { FatalError( "node::StreamWrapCallbacks::DoAlloc(uv_handle_t*, size_t, uv_buf_t*)", "Out Of Memory"); @@ -685,14 +685,14 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle, }; if (nread < 0) { - if (buf->base != NULL) + if (buf->base != nullptr) free(buf->base); wrap()->MakeCallback(env->onread_string(), ARRAY_SIZE(argv), argv); return; } if (nread == 0) { - if (buf->base != NULL) + if (buf->base != nullptr) free(buf->base); return; } diff --git a/src/stream_wrap.h b/src/stream_wrap.h index adf457e2a1..3c058d26f8 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -164,7 +164,7 @@ class StreamWrap : public HandleWrap { if (!callbacks_gc_ && callbacks_ != &default_callbacks_) { delete callbacks_; } - callbacks_ = NULL; + callbacks_ = nullptr; } void StateChange() { } diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 7986752d7f..43bf10704a 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -296,7 +296,7 @@ size_t StringBytes::Write(Isolate* isolate, enum encoding encoding, int* chars_written) { HandleScope scope(isolate); - const char* data = NULL; + const char* data = nullptr; size_t len = 0; bool is_extern = GetExternalParts(isolate, val, &data, &len); size_t extlen = len; @@ -319,7 +319,7 @@ size_t StringBytes::Write(Isolate* isolate, 0, buflen, flags); - if (chars_written != NULL) + if (chars_written != nullptr) *chars_written = len; break; @@ -347,7 +347,7 @@ size_t StringBytes::Write(Isolate* isolate, buf16[i] = (buf16[i] << 8) | (buf16[i] >> 8); } } - if (chars_written != NULL) + if (chars_written != nullptr) *chars_written = len; len = len * sizeof(uint16_t); break; @@ -359,7 +359,7 @@ size_t StringBytes::Write(Isolate* isolate, String::Value value(str); len = base64_decode(buf, buflen, *value, value.length()); } - if (chars_written != NULL) { + if (chars_written != nullptr) { *chars_written = len; } break; @@ -371,7 +371,7 @@ size_t StringBytes::Write(Isolate* isolate, String::Value value(str); len = hex_decode(buf, buflen, *value, value.length()); } - if (chars_written != NULL) { + if (chars_written != nullptr) { *chars_written = len * 2; } break; @@ -749,7 +749,7 @@ Local<Value> StringBytes::Encode(Isolate* isolate, case UCS2: { const uint16_t* out = reinterpret_cast<const uint16_t*>(buf); - uint16_t* dst = NULL; + uint16_t* dst = nullptr; if (IsBigEndian()) { // Node's "ucs2" encoding expects LE character data inside a // Buffer, so we need to reorder on BE platforms. See diff --git a/src/string_bytes.h b/src/string_bytes.h index 77ae5b9421..10fee30913 100644 --- a/src/string_bytes.h +++ b/src/string_bytes.h @@ -68,7 +68,7 @@ class StringBytes { size_t buflen, v8::Handle<v8::Value> val, enum encoding enc, - int* chars_written = NULL); + int* chars_written = nullptr); // Take the bytes in the src, and turn it into a Buffer or String. static v8::Local<v8::Value> Encode(v8::Isolate* isolate, @@ -109,7 +109,7 @@ class StringBytes { size_t buflen, v8::Handle<v8::Value> val, enum encoding enc, - int* chars_written = NULL) { + int* chars_written = nullptr) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); return Write(isolate, buf, buflen, val, enc, chars_written); }) diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 1a4939f63c..4da37ab66f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -79,7 +79,7 @@ void TCPWrap::Initialize(Handle<Object> target, static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); t->InstanceTemplate()->SetAccessor(env->fd_string(), StreamWrap::GetFD, - NULL, + nullptr, Handle<Value>(), v8::DEFAULT, attributes); diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 0155505532..dfa551d05c 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -140,7 +140,7 @@ class TimerWrap : public HandleWrap { Environment* env = wrap->env(); HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); - wrap->MakeCallback(kOnTimeout, 0, NULL); + wrap->MakeCallback(kOnTimeout, 0, nullptr); } static void Now(const FunctionCallbackInfo<Value>& args) { diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index bc53100812..41e6c10051 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -68,14 +68,14 @@ TLSCallbacks::TLSCallbacks(Environment* env, AsyncWrap::PROVIDER_TLSWRAP), sc_(Unwrap<SecureContext>(sc)), sc_handle_(env->isolate(), sc), - enc_in_(NULL), - enc_out_(NULL), - clear_in_(NULL), + enc_in_(nullptr), + enc_out_(nullptr), + clear_in_(nullptr), write_size_(0), started_(false), established_(false), shutdown_(false), - error_(NULL), + error_(nullptr), cycle_depth_(0), eof_(false) { node::Wrap<TLSCallbacks>(object(), this); @@ -94,12 +94,12 @@ TLSCallbacks::TLSCallbacks(Environment* env, TLSCallbacks::~TLSCallbacks() { - enc_in_ = NULL; - enc_out_ = NULL; + enc_in_ = nullptr; + enc_out_ = nullptr; delete clear_in_; - clear_in_ = NULL; + clear_in_ = nullptr; - sc_ = NULL; + sc_ = nullptr; sc_handle_.Reset(); persistent().Reset(); @@ -224,13 +224,13 @@ void TLSCallbacks::Wrap(const FunctionCallbackInfo<Value>& args) { Kind kind = args[2]->IsTrue() ? SSLWrap<TLSCallbacks>::kServer : SSLWrap<TLSCallbacks>::kClient; - TLSCallbacks* callbacks = NULL; + TLSCallbacks* callbacks = nullptr; WITH_GENERIC_STREAM(env, stream, { callbacks = new TLSCallbacks(env, kind, sc, wrap->callbacks()); wrap->OverrideCallbacks(callbacks, true); }); - if (callbacks == NULL) { + if (callbacks == nullptr) { return args.GetReturnValue().SetNull(); } @@ -294,7 +294,7 @@ void TLSCallbacks::SSLInfoCallback(const SSL* ssl_, int where, int ret) { if (where & SSL_CB_HANDSHAKE_START) { Local<Value> callback = object->Get(env->onhandshakestart_string()); if (callback->IsFunction()) { - c->MakeCallback(callback.As<Function>(), 0, NULL); + c->MakeCallback(callback.As<Function>(), 0, nullptr); } } @@ -302,7 +302,7 @@ void TLSCallbacks::SSLInfoCallback(const SSL* ssl_, int where, int ret) { c->established_ = true; Local<Value> callback = object->Get(env->onhandshakedone_string()); if (callback->IsFunction()) { - c->MakeCallback(callback.As<Function>(), 0, NULL); + c->MakeCallback(callback.As<Function>(), 0, nullptr); } } } @@ -370,7 +370,7 @@ void TLSCallbacks::EncOutCb(uv_write_t* req, int status) { } // Commit - NodeBIO::FromBIO(callbacks->enc_out_)->Read(NULL, callbacks->write_size_); + NodeBIO::FromBIO(callbacks->enc_out_)->Read(nullptr, callbacks->write_size_); // Try writing more data callbacks->write_size_ = 0; @@ -426,8 +426,8 @@ Local<Value> TLSCallbacks::GetSSLError(int status, int* err, const char** msg) { OneByteString(env()->isolate(), buf, strlen(buf)); Local<Value> exception = Exception::Error(message); - if (msg != NULL) { - CHECK_EQ(*msg, NULL); + if (msg != nullptr) { + CHECK_EQ(*msg, nullptr); *msg = buf; } @@ -450,7 +450,7 @@ void TLSCallbacks::ClearOut() { HandleScope handle_scope(env()->isolate()); Context::Scope context_scope(env()->context()); - CHECK_NE(ssl_, NULL); + CHECK_NE(ssl_, nullptr); char out[kClearOutChunkSize]; int read; @@ -474,7 +474,7 @@ void TLSCallbacks::ClearOut() { if (read == -1) { int err; - Local<Value> arg = GetSSLError(read, &err, NULL); + Local<Value> arg = GetSSLError(read, &err, nullptr); // Ignore ZERO_RETURN after EOF, it is basically not a error if (err == SSL_ERROR_ZERO_RETURN && eof_) @@ -505,7 +505,7 @@ bool TLSCallbacks::ClearIn() { CHECK(written == -1 || written == static_cast<int>(avail)); if (written == -1) break; - clear_in_->Read(NULL, avail); + clear_in_->Read(nullptr, avail); } // All written @@ -523,7 +523,7 @@ bool TLSCallbacks::ClearIn() { if (!arg.IsEmpty()) { MakePending(); if (!InvokeQueued(UV_EPROTO)) - error_ = NULL; + error_ = nullptr; clear_in_->Reset(); } @@ -533,7 +533,7 @@ bool TLSCallbacks::ClearIn() { const char* TLSCallbacks::Error() { const char* ret = error_; - error_ = NULL; + error_ = nullptr; return ret; } @@ -549,7 +549,7 @@ int TLSCallbacks::DoWrite(WriteWrap* w, size_t count, uv_stream_t* send_handle, uv_write_cb cb) { - CHECK_EQ(send_handle, NULL); + CHECK_EQ(send_handle, nullptr); bool empty = true; @@ -651,7 +651,7 @@ void TLSCallbacks::DoRead(uv_stream_t* handle, } // Only client connections can receive data - CHECK_NE(ssl_, NULL); + CHECK_NE(ssl_, nullptr); // Commit read data NodeBIO* enc_in = NodeBIO::FromBIO(enc_in_); @@ -661,7 +661,7 @@ void TLSCallbacks::DoRead(uv_stream_t* handle, if (!hello_parser_.IsEnded()) { size_t avail = 0; uint8_t* data = reinterpret_cast<uint8_t*>(enc_in->Peek(&avail)); - CHECK(avail == 0 || data != NULL); + CHECK(avail == 0 || data != nullptr); return hello_parser_.Parse(data, avail); } @@ -740,7 +740,7 @@ void TLSCallbacks::GetServername(const FunctionCallbackInfo<Value>& args) { const char* servername = SSL_get_servername(wrap->ssl_, TLSEXT_NAMETYPE_host_name); - if (servername != NULL) { + if (servername != nullptr) { args.GetReturnValue().Set(OneByteString(env->isolate(), servername)); } else { args.GetReturnValue().Set(false); @@ -775,7 +775,7 @@ int TLSCallbacks::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { const char* servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); - if (servername == NULL) + if (servername == nullptr) return SSL_TLSEXT_ERR_OK; HandleScope scope(env->isolate()); diff --git a/src/tls_wrap.h b/src/tls_wrap.h index b12a6b6612..598288c621 100644 --- a/src/tls_wrap.h +++ b/src/tls_wrap.h @@ -89,8 +89,8 @@ class TLSCallbacks : public crypto::SSLWrap<TLSCallbacks>, WriteItem(WriteWrap* w, uv_write_cb cb) : w_(w), cb_(cb) { } ~WriteItem() { - w_ = NULL; - cb_ = NULL; + w_ = nullptr; + cb_ = nullptr; } WriteWrap* w_; diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 1e5eff3a67..cf1c72c646 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -60,7 +60,7 @@ void TTYWrap::Initialize(Handle<Object> target, static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); t->InstanceTemplate()->SetAccessor(env->fd_string(), StreamWrap::GetFD, - NULL, + nullptr, Handle<Value>(), v8::DEFAULT, attributes); @@ -99,7 +99,7 @@ void TTYWrap::GuessHandleType(const FunctionCallbackInfo<Value>& args) { CHECK_GE(fd, 0); uv_handle_type t = uv_guess_handle(fd); - const char* type = NULL; + const char* type = nullptr; switch (t) { case UV_TCP: type = "TCP"; break; diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index d41567d25c..1698ecf645 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -99,7 +99,7 @@ void UDPWrap::Initialize(Handle<Object> target, static_cast<PropertyAttribute>(v8::ReadOnly | v8::DontDelete); t->InstanceTemplate()->SetAccessor(env->fd_string(), UDPWrap::GetFD, - NULL, + nullptr, Handle<Value>(), v8::DEFAULT, attributes); @@ -138,7 +138,7 @@ void UDPWrap::GetFD(Local<String>, const PropertyCallbackInfo<Value>& args) { #if !defined(_WIN32) HandleScope scope(args.GetIsolate()); UDPWrap* wrap = Unwrap<UDPWrap>(args.Holder()); - int fd = (wrap == NULL) ? -1 : wrap->handle_.io_watcher.fd; + int fd = (wrap == nullptr) ? -1 : wrap->handle_.io_watcher.fd; args.GetReturnValue().Set(fd); #endif } @@ -216,7 +216,7 @@ void UDPWrap::SetMembership(const FunctionCallbackInfo<Value>& args, const char* iface_cstr = *iface; if (args[1]->IsUndefined() || args[1]->IsNull()) { - iface_cstr = NULL; + iface_cstr = nullptr; } int err = uv_udp_set_membership(&wrap->handle_, @@ -367,7 +367,7 @@ void UDPWrap::OnAlloc(uv_handle_t* handle, buf->base = static_cast<char*>(malloc(suggested_size)); buf->len = suggested_size; - if (buf->base == NULL && suggested_size > 0) { + if (buf->base == nullptr && suggested_size > 0) { FatalError("node::UDPWrap::OnAlloc(uv_handle_t*, size_t, uv_buf_t*)", "Out Of Memory"); } @@ -379,8 +379,8 @@ void UDPWrap::OnRecv(uv_udp_t* handle, const uv_buf_t* buf, const struct sockaddr* addr, unsigned int flags) { - if (nread == 0 && addr == NULL) { - if (buf->base != NULL) + if (nread == 0 && addr == nullptr) { + if (buf->base != nullptr) free(buf->base); return; } @@ -400,7 +400,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, }; if (nread < 0) { - if (buf->base != NULL) + if (buf->base != nullptr) free(buf->base); wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv); return; diff --git a/src/util-inl.h b/src/util-inl.h index 6035cadc09..b0264fbbd2 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -106,7 +106,7 @@ void Wrap(v8::Local<v8::Object> object, TypeName* pointer) { } void ClearWrap(v8::Local<v8::Object> object) { - Wrap<void>(object, NULL); + Wrap<void>(object, nullptr); } template <typename TypeName> diff --git a/src/util.cc b/src/util.cc index 67c9664530..5a652663c8 100644 --- a/src/util.cc +++ b/src/util.cc @@ -26,7 +26,7 @@ namespace node { Utf8Value::Utf8Value(v8::Handle<v8::Value> value) - : length_(0), str_(NULL) { + : length_(0), str_(nullptr) { if (value.IsEmpty()) return; |