Skip to content

Commit

Permalink
src: use nullptr instead of NULL
Browse files Browse the repository at this point in the history
PR-URL: nodejs#17373
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
danbev committed Dec 1, 2017
1 parent 85e34b0 commit e32bbbf
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ int inspector_accept(uv_stream_t* server, InspectorSocket* socket,
data_received_cb);
}
if (err != 0) {
uv_close(reinterpret_cast<uv_handle_t*>(tcp), NULL);
uv_close(reinterpret_cast<uv_handle_t*>(tcp), nullptr);
}
return err;
}
Expand Down
6 changes: 3 additions & 3 deletions src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void PrintDebuggerReadyMessage(const std::string& host,
int port,
const std::vector<std::string>& ids,
FILE* out) {
if (out == NULL) {
if (out == nullptr) {
return;
}
for (const std::string& id : ids) {
Expand Down Expand Up @@ -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));
}
Expand All @@ -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_);
Expand Down
32 changes: 16 additions & 16 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ namespace node {

NODE_EXTERN v8::Local<v8::Value> 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<v8::Value> 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<v8::Value> UVException(v8::Isolate* isolate,
int errorno,
const char* syscall,
Expand All @@ -126,9 +126,9 @@ NODE_EXTERN v8::Local<v8::Value> UVException(v8::Isolate* isolate,
NODE_DEPRECATED("Use ErrnoException(isolate, ...)",
inline v8::Local<v8::Value> 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,
Expand All @@ -137,9 +137,9 @@ NODE_DEPRECATED("Use ErrnoException(isolate, ...)",
})

inline v8::Local<v8::Value> 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,
Expand Down Expand Up @@ -426,14 +426,14 @@ NODE_DEPRECATED("Use DecodeWrite(isolate, ...)",
NODE_EXTERN v8::Local<v8::Value> 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<v8::Value> 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,
Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ static void EncodeUtf8String(const FunctionCallbackInfo<Value>& 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);
Expand Down
12 changes: 7 additions & 5 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ static bool SafeX509ExtPrint(BIO* out, X509_EXTENSION* ext) {
return false;

GENERAL_NAMES* names = static_cast<GENERAL_NAMES*>(X509V3_EXT_d2i(ext));
if (names == NULL)
if (names == nullptr)
return false;

for (int i = 0; i < sk_GENERAL_NAME_num(names); i++) {
Expand All @@ -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<X509V3_EXT_METHOD*>(method), gen, NULL);
if (nval == NULL)
const_cast<X509V3_EXT_METHOD*>(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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ void Http2Session::Goaway(const FunctionCallbackInfo<Value>& args) {
int32_t lastStreamID = args[1]->Int32Value(context).ToChecked();
Local<Value> opaqueData = args[2];

uint8_t* data = NULL;
uint8_t* data = nullptr;
size_t length = 0;

if (opaqueData->BooleanValue(context).ToChecked()) {
Expand Down
14 changes: 7 additions & 7 deletions src/node_i18n.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@ MaybeLocal<Object> ToBufferEndian(Environment* env, MaybeStackBuffer<T>* 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);
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -254,7 +254,7 @@ class ConverterObject : public BaseObject, Converter {
v8::Local<v8::Object> wrap,
UConverter* converter,
bool ignoreBOM,
const char* sub = NULL) :
const char* sub = nullptr) :
BaseObject(env, wrap),
Converter(converter, sub),
ignoreBOM_(ignoreBOM) {
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
&error);
MaybeLocal<Value> shell;

if (pwd.shell == NULL)
if (pwd.shell == nullptr)
shell = Null(env->isolate());
else
shell = StringBytes::Encode(env->isolate(), pwd.shell, encoding, &error);
Expand Down
2 changes: 1 addition & 1 deletion src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/node_trace_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/node_trace_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/addons/repl-domain-abort/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Method(const FunctionCallbackInfo<Value>& args) {
isolate->GetCurrentContext()->Global(),
args[0].As<Function>(),
0,
NULL);
nullptr);
}

void init(Local<Object> exports) {
Expand Down
4 changes: 2 additions & 2 deletions test/cctest/test_inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class ServerHolder {
public:
template <typename Delegate>
ServerHolder(Delegate* delegate, uv_loop_t* loop, int port)
: ServerHolder(delegate, loop, HOST, port, NULL) { }
: ServerHolder(delegate, loop, HOST, port, nullptr) { }

template <typename Delegate>
ServerHolder(Delegate* delegate, uv_loop_t* loop, const std::string host,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e32bbbf

Please sign in to comment.