Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: use nullptr instead of NULL #17373

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 24 additions & 23 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 Expand Up @@ -501,13 +501,13 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
{ \
NODE_MODULE_VERSION, \
flags, \
NULL, \
NULL, /* NOLINT (readability/null_usage) */ \
__FILE__, \
(node::addon_register_func) (regfunc), \
NULL, \
NULL, /* NOLINT (readability/null_usage) */ \
NODE_STRINGIFY(modname), \
priv, \
NULL \
NULL /* NOLINT (readability/null_usage) */ \
}; \
NODE_C_CTOR(_register_ ## modname) { \
node_module_register(&_module); \
Expand All @@ -520,23 +520,24 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
{ \
NODE_MODULE_VERSION, \
flags, \
NULL, \
NULL, /* NOLINT (readability/null_usage) */ \
__FILE__, \
NULL, \
NULL, /* NOLINT (readability/null_usage) */ \
(node::addon_context_register_func) (regfunc), \
NODE_STRINGIFY(modname), \
priv, \
NULL \
NULL /* NOLINT (readability/null_usage) */ \
}; \
NODE_C_CTOR(_register_ ## modname) { \
node_module_register(&_module); \
} \
}

#define NODE_MODULE(modname, regfunc) \
NODE_MODULE_X(modname, regfunc, NULL, 0)
NODE_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)

#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \
/* NOLINTNEXTLINE (readability/null_usage) */ \
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)

/*
Expand Down
2 changes: 1 addition & 1 deletion src/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef struct {
EXTERN_C_END

#define NAPI_MODULE(modname, regfunc) \
NAPI_MODULE_X(modname, regfunc, NULL, 0)
NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)

#define NAPI_AUTO_LENGTH SIZE_MAX

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
2 changes: 1 addition & 1 deletion src/node_win32_etw_provider-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extern int events_enabled;
DWORD status = event_write(node_provider, \
&eventDescriptor, \
0, \
NULL); \
NULL); // NOLINT (readability/null_usage) \
CHECK_EQ(status, ERROR_SUCCESS);


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
1 change: 1 addition & 0 deletions test/addons-napi/7_factory_wrap/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ napi_value Init(napi_env env, napi_value exports) {
NAPI_CALL(env, MyObject::Init(env));

NAPI_CALL(env,
// NOLINTNEXTLINE (readability/null_usage)
napi_create_function(env, "exports", -1, CreateObject, NULL, &exports));
return exports;
}
Expand Down
2 changes: 2 additions & 0 deletions test/addons-napi/test_make_callback/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
const int kMaxArgs = 10;
size_t argc = kMaxArgs;
napi_value args[kMaxArgs];
// NOLINTNEXTLINE (readability/null_usage)
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));

NAPI_ASSERT(env, argc > 0, "Wrong number of arguments");
Expand Down Expand Up @@ -47,6 +48,7 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
napi_value Init(napi_env env, napi_value exports) {
napi_value fn;
NAPI_CALL(env, napi_create_function(
// NOLINTNEXTLINE (readability/null_usage)
env, NULL, NAPI_AUTO_LENGTH, MakeCallback, NULL, &fn));
NAPI_CALL(env, napi_set_named_property(env, exports, "makeCallback", fn));
return exports;
Expand Down
2 changes: 2 additions & 0 deletions test/addons-napi/test_make_callback_recurse/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace {
napi_value MakeCallback(napi_env env, napi_callback_info info) {
size_t argc = 2;
napi_value args[2];
// NOLINTNEXTLINE (readability/null_usage)
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));

napi_value recv = args[0];
Expand All @@ -21,6 +22,7 @@ napi_value MakeCallback(napi_env env, napi_callback_info info) {
napi_value Init(napi_env env, napi_value exports) {
napi_value fn;
NAPI_CALL(env, napi_create_function(
// NOLINTNEXTLINE (readability/null_usage)
env, NULL, NAPI_AUTO_LENGTH, MakeCallback, NULL, &fn));
NAPI_CALL(env, napi_set_named_property(env, exports, "makeCallback", fn));
return exports;
Expand Down
Loading