From e32bbbf4d7adfdb22822c39991ea0e972a0a3453 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 27 Nov 2017 09:19:11 +0100 Subject: [PATCH] src: use nullptr instead of NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/17373 Reviewed-By: Jon Moss Reviewed-By: Anna Henningsen Reviewed-By: Timothy Gu Reviewed-By: Colin Ihrig Reviewed-By: Michael Dawson Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Tobias Nießen --- src/cares_wrap.cc | 4 +-- src/inspector_socket.cc | 2 +- src/inspector_socket_server.cc | 6 ++-- src/node.h | 32 ++++++++++----------- src/node_buffer.cc | 2 +- src/node_crypto.cc | 12 ++++---- src/node_http2.cc | 2 +- src/node_i18n.cc | 14 ++++----- src/node_os.cc | 2 +- src/node_url.cc | 2 +- src/tracing/node_trace_buffer.cc | 6 ++-- src/tracing/node_trace_writer.cc | 2 +- src/tracing/trace_event.h | 2 +- test/addons/repl-domain-abort/binding.cc | 2 +- test/cctest/test_inspector_socket_server.cc | 4 +-- 15 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 6d16cce2c87f10..3fb98c293c23d7 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -798,7 +798,7 @@ int ParseGeneralReply(Environment* env, status = ares_parse_ns_reply(buf, len, &host); break; case ns_t_ptr: - status = ares_parse_ptr_reply(buf, len, NULL, 0, AF_INET, &host); + status = ares_parse_ptr_reply(buf, len, nullptr, 0, AF_INET, &host); break; default: CHECK(0 && "Bad NS type"); @@ -830,7 +830,7 @@ int ParseGeneralReply(Environment* env, HostentToNames(env, host, ret); } else if (*type == ns_t_ptr) { uint32_t offset = ret->Length(); - for (uint32_t i = 0; host->h_aliases[i] != NULL; i++) { + for (uint32_t i = 0; host->h_aliases[i] != nullptr; i++) { ret->Set(context, i + offset, OneByteString(env->isolate(), host->h_aliases[i])).FromJust(); diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index 265b37616138dc..49d337b70b1198 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -577,7 +577,7 @@ int inspector_accept(uv_stream_t* server, InspectorSocket* socket, data_received_cb); } if (err != 0) { - uv_close(reinterpret_cast(tcp), NULL); + uv_close(reinterpret_cast(tcp), nullptr); } return err; } diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc index cdc907ee9b263b..958c41a654adff 100644 --- a/src/inspector_socket_server.cc +++ b/src/inspector_socket_server.cc @@ -94,7 +94,7 @@ void PrintDebuggerReadyMessage(const std::string& host, int port, const std::vector& ids, FILE* out) { - if (out == NULL) { + if (out == nullptr) { return; } for (const std::string& id : ids) { @@ -398,7 +398,7 @@ bool InspectorSocketServer::Start() { int err = uv_getaddrinfo(loop_, &req, nullptr, host_.c_str(), port_string.c_str(), &hints); if (err < 0) { - if (out_ != NULL) { + if (out_ != nullptr) { fprintf(out_, "Unable to resolve \"%s\": %s\n", host_.c_str(), uv_strerror(err)); } @@ -416,7 +416,7 @@ bool InspectorSocketServer::Start() { // We only show error if we failed to start server on all addresses. We only // show one error, for the last address. if (server_sockets_.empty()) { - if (out_ != NULL) { + if (out_ != nullptr) { fprintf(out_, "Starting inspector on %s:%d failed: %s\n", host_.c_str(), port_, uv_strerror(err)); fflush(out_); diff --git a/src/node.h b/src/node.h index 583e58cea47383..9ce8664c98e998 100644 --- a/src/node.h +++ b/src/node.h @@ -108,14 +108,14 @@ namespace node { NODE_EXTERN v8::Local ErrnoException(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_EXTERN v8::Local UVException(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_EXTERN v8::Local UVException(v8::Isolate* isolate, int errorno, const char* syscall, @@ -126,9 +126,9 @@ NODE_EXTERN v8::Local UVException(v8::Isolate* isolate, NODE_DEPRECATED("Use ErrnoException(isolate, ...)", inline v8::Local ErrnoException( 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) { return ErrnoException(v8::Isolate::GetCurrent(), errorno, syscall, @@ -137,9 +137,9 @@ NODE_DEPRECATED("Use ErrnoException(isolate, ...)", }) inline v8::Local UVException(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) { return UVException(v8::Isolate::GetCurrent(), errorno, syscall, @@ -426,14 +426,14 @@ NODE_DEPRECATED("Use DecodeWrite(isolate, ...)", NODE_EXTERN v8::Local WinapiErrnoException( v8::Isolate* isolate, int errorno, - const char *syscall = NULL, + const char *syscall = nullptr, const char *msg = "", - const char *path = NULL); + const char *path = nullptr); NODE_DEPRECATED("Use WinapiErrnoException(isolate, ...)", inline v8::Local WinapiErrnoException(int errorno, - const char *syscall = NULL, const char *msg = "", - const char *path = NULL) { + const char *syscall = nullptr, const char *msg = "", + const char *path = nullptr) { return WinapiErrnoException(v8::Isolate::GetCurrent(), errorno, syscall, diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 008ac469185b55..138c26685fcffc 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -1210,7 +1210,7 @@ static void EncodeUtf8String(const FunctionCallbackInfo& args) { char* data = node::UncheckedMalloc(length); str->WriteUtf8(data, -1, // We are certain that `data` is sufficiently large - NULL, + nullptr, String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8); auto array_buf = ArrayBuffer::New(env->isolate(), data, length, ArrayBufferCreationMode::kInternalized); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 23dd4a21b8ccbd..88d10bee788e1a 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1775,7 +1775,7 @@ static bool SafeX509ExtPrint(BIO* out, X509_EXTENSION* ext) { return false; GENERAL_NAMES* names = static_cast(X509V3_EXT_d2i(ext)); - if (names == NULL) + if (names == nullptr) return false; for (int i = 0; i < sk_GENERAL_NAME_num(names); i++) { @@ -1791,8 +1791,8 @@ static bool SafeX509ExtPrint(BIO* out, X509_EXTENSION* ext) { BIO_write(out, name->data, name->length); } else { STACK_OF(CONF_VALUE)* nval = i2v_GENERAL_NAME( - const_cast(method), gen, NULL); - if (nval == NULL) + const_cast(method), gen, nullptr); + if (nval == nullptr) return false; X509V3_EXT_val_prn(out, nval, 0, 0); sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); @@ -6094,7 +6094,7 @@ void InitCryptoOnce() { if (0 != err) { fprintf(stderr, "openssl config failed: %s\n", - ERR_error_string(err, NULL)); + ERR_error_string(err, nullptr)); CHECK_NE(err, 0); } } @@ -6117,7 +6117,9 @@ void InitCryptoOnce() { } } if (0 != err) { - fprintf(stderr, "openssl fips failed: %s\n", ERR_error_string(err, NULL)); + fprintf(stderr, + "openssl fips failed: %s\n", + ERR_error_string(err, nullptr)); UNREACHABLE(); } #endif // NODE_FIPS_MODE diff --git a/src/node_http2.cc b/src/node_http2.cc index 465c045c661dad..b763ff0dbe5ab1 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1792,7 +1792,7 @@ void Http2Session::Goaway(const FunctionCallbackInfo& args) { int32_t lastStreamID = args[1]->Int32Value(context).ToChecked(); Local opaqueData = args[2]; - uint8_t* data = NULL; + uint8_t* data = nullptr; size_t length = 0; if (opaqueData->BooleanValue(context).ToChecked()) { diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 101ae4c79e42d2..041eda94f3bdd5 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -114,21 +114,21 @@ MaybeLocal ToBufferEndian(Environment* env, MaybeStackBuffer* buf) { } struct Converter { - explicit Converter(const char* name, const char* sub = NULL) + explicit Converter(const char* name, const char* sub = nullptr) : conv(nullptr) { UErrorCode status = U_ZERO_ERROR; conv = ucnv_open(name, &status); CHECK(U_SUCCESS(status)); - if (sub != NULL) { + if (sub != nullptr) { ucnv_setSubstChars(conv, sub, strlen(sub), &status); } } explicit Converter(UConverter* converter, - const char* sub = NULL) : conv(converter) { + const char* sub = nullptr) : conv(converter) { CHECK_NE(conv, nullptr); UErrorCode status = U_ZERO_ERROR; - if (sub != NULL) { + if (sub != nullptr) { ucnv_setSubstChars(conv, sub, strlen(sub), &status); } } @@ -229,7 +229,7 @@ class ConverterObject : public BaseObject, Converter { ucnv_toUnicode(converter->conv, &target, target + (limit * sizeof(UChar)), &source, source + source_length, - NULL, flush, &status); + nullptr, flush, &status); if (U_SUCCESS(status)) { if (limit > 0) @@ -254,7 +254,7 @@ class ConverterObject : public BaseObject, Converter { v8::Local wrap, UConverter* converter, bool ignoreBOM, - const char* sub = NULL) : + const char* sub = nullptr) : BaseObject(env, wrap), Converter(converter, sub), ignoreBOM_(ignoreBOM) { @@ -427,7 +427,7 @@ const char* EncodingName(const enum encoding encoding) { case LATIN1: return "iso8859-1"; case UCS2: return "utf16le"; case UTF8: return "utf-8"; - default: return NULL; + default: return nullptr; } } diff --git a/src/node_os.cc b/src/node_os.cc index f6dbf76b4c8602..6698531998c852 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -382,7 +382,7 @@ static void GetUserInfo(const FunctionCallbackInfo& args) { &error); MaybeLocal shell; - if (pwd.shell == NULL) + if (pwd.shell == nullptr) shell = Null(env->isolate()); else shell = StringBytes::Encode(env->isolate(), pwd.shell, encoding, &error); diff --git a/src/node_url.cc b/src/node_url.cc index c9c8ccd579744e..e1ef9273ae927e 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -752,7 +752,7 @@ static inline int64_t ParseNumber(const char* start, const char* end) { } p++; } - return strtoll(start, NULL, R); + return strtoll(start, nullptr, R); } static url_host_type ParseIPv4Host(url_host* host, diff --git a/src/tracing/node_trace_buffer.cc b/src/tracing/node_trace_buffer.cc index c8d71b762ef1de..4c9f7c658fd945 100644 --- a/src/tracing/node_trace_buffer.cc +++ b/src/tracing/node_trace_buffer.cc @@ -32,7 +32,7 @@ TraceObject* InternalTraceBuffer::GetEventByHandle(uint64_t handle) { Mutex::ScopedLock scoped_lock(mutex_); if (handle == 0) { // A handle value of zero never has a trace event associated with it. - return NULL; + return nullptr; } size_t chunk_index, event_index; uint32_t buffer_id, chunk_seq; @@ -41,12 +41,12 @@ TraceObject* InternalTraceBuffer::GetEventByHandle(uint64_t handle) { // Either the chunk belongs to the other buffer, or is outside the current // range of chunks loaded in memory (the latter being true suggests that // the chunk has already been flushed and is no longer in memory.) - return NULL; + return nullptr; } auto& chunk = chunks_[chunk_index]; if (chunk->seq() != chunk_seq) { // Chunk is no longer in memory. - return NULL; + return nullptr; } return chunk->GetEventAt(event_index); } diff --git a/src/tracing/node_trace_writer.cc b/src/tracing/node_trace_writer.cc index ff3c981d103d09..9293e9cb8f7b4a 100644 --- a/src/tracing/node_trace_writer.cc +++ b/src/tracing/node_trace_writer.cc @@ -60,7 +60,7 @@ void NodeTraceWriter::OpenNewFileForStreaming() { std::ostringstream log_file; log_file << "node_trace." << file_num_ << ".log"; fd_ = uv_fs_open(tracing_loop_, &req, log_file.str().c_str(), - O_CREAT | O_WRONLY | O_TRUNC, 0644, NULL); + O_CREAT | O_WRONLY | O_TRUNC, 0644, nullptr); CHECK_NE(fd_, -1); uv_fs_req_cleanup(&req); } diff --git a/src/tracing/trace_event.h b/src/tracing/trace_event.h index 2b4c1e36cf9156..44a30f38e59394 100644 --- a/src/tracing/trace_event.h +++ b/src/tracing/trace_event.h @@ -518,7 +518,7 @@ static inline uint64_t AddTraceEvent( class ScopedTracer { public: // Note: members of data_ intentionally left uninitialized. See Initialize. - ScopedTracer() : p_data_(NULL) {} + ScopedTracer() : p_data_(nullptr) {} ~ScopedTracer() { if (p_data_ && *data_.category_group_enabled) diff --git a/test/addons/repl-domain-abort/binding.cc b/test/addons/repl-domain-abort/binding.cc index d6a825dfdd5dd8..1b4dbfa84e5054 100644 --- a/test/addons/repl-domain-abort/binding.cc +++ b/test/addons/repl-domain-abort/binding.cc @@ -35,7 +35,7 @@ void Method(const FunctionCallbackInfo& args) { isolate->GetCurrentContext()->Global(), args[0].As(), 0, - NULL); + nullptr); } void init(Local exports) { diff --git a/test/cctest/test_inspector_socket_server.cc b/test/cctest/test_inspector_socket_server.cc index 5eff9d706b2a3a..ab74917234eefb 100644 --- a/test/cctest/test_inspector_socket_server.cc +++ b/test/cctest/test_inspector_socket_server.cc @@ -313,7 +313,7 @@ class ServerHolder { public: template ServerHolder(Delegate* delegate, uv_loop_t* loop, int port) - : ServerHolder(delegate, loop, HOST, port, NULL) { } + : ServerHolder(delegate, loop, HOST, port, nullptr) { } template ServerHolder(Delegate* delegate, uv_loop_t* loop, const std::string host, @@ -617,7 +617,7 @@ TEST_F(InspectorSocketServerTest, BindsToIpV6) { return; } TestInspectorServerDelegate delegate; - ServerHolder server(&delegate, &loop, "::", 0, NULL); + ServerHolder server(&delegate, &loop, "::", 0, nullptr); ASSERT_TRUE(server->Start()); SocketWrapper socket1(&loop);