From 2fd8be2dbe5480966d8082044c553167532e49b7 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 31 Mar 2016 12:47:06 +0200 Subject: [PATCH] src: replace ARRAY_SIZE with typesafe arraysize To prevent `ARRAY_SIZE(&arg)` (i.e., taking the array size of a pointer) from happening again. PR-URL: https://github.com/nodejs/node/pull/5969 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- src/async-wrap-inl.h | 2 +- src/async-wrap.cc | 2 +- src/cares_wrap.cc | 8 ++++---- src/debug-agent.cc | 8 ++++---- src/fs_event_wrap.cc | 2 +- src/js_stream.cc | 4 ++-- src/node.cc | 26 +++++++++++++------------- src/node_contextify.cc | 2 +- src/node_counters.cc | 2 +- src/node_crypto.cc | 22 +++++++++++----------- src/node_dtrace.cc | 2 +- src/node_file.cc | 8 ++++---- src/node_http_parser.cc | 16 ++++++++-------- src/node_internals.h | 7 +++++-- src/node_lttng.cc | 2 +- src/node_stat_watcher.cc | 2 +- src/node_win32_etw_provider-inl.h | 2 +- src/node_win32_etw_provider.cc | 2 +- src/node_zlib.cc | 4 ++-- src/pipe_wrap.cc | 6 +++--- src/process_wrap.cc | 2 +- src/stream_base.cc | 10 +++++----- src/tcp_wrap.cc | 4 ++-- src/tls_wrap.cc | 6 +++--- src/udp_wrap.cc | 6 +++--- 25 files changed, 80 insertions(+), 77 deletions(-) diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index e61e2ad4bfbf63..cf7024e7e31461 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -54,7 +54,7 @@ inline AsyncWrap::AsyncWrap(Environment* env, v8::TryCatch try_catch(env->isolate()); v8::MaybeLocal ret = - init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv); + init_fn->Call(env->context(), object, arraysize(argv), argv); if (ret.IsEmpty()) { ClearFatalExceptionHandlers(env); diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 05ee7fa02ad035..8129500a922d97 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -242,7 +242,7 @@ Local AsyncWrap::MakeCallback(const Local cb, Local vals[] = { uid, did_throw }; TryCatch try_catch(env()->isolate()); MaybeLocal ar = - post_fn->Call(env()->context(), context, ARRAY_SIZE(vals), vals); + post_fn->Call(env()->context(), context, arraysize(vals), vals); if (ar.IsEmpty()) { ClearFatalExceptionHandlers(env()); FatalException(env()->isolate(), try_catch); diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index ade257963fe415..50ec19cb179af7 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -310,7 +310,7 @@ class QueryWrap : public AsyncWrap { Integer::New(env()->isolate(), 0), answer }; - MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv); + MakeCallback(env()->oncomplete_string(), arraysize(argv), argv); } void CallOnComplete(Local answer, Local family) { @@ -321,7 +321,7 @@ class QueryWrap : public AsyncWrap { answer, family }; - MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv); + MakeCallback(env()->oncomplete_string(), arraysize(argv), argv); } void ParseError(int status) { @@ -994,7 +994,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { uv_freeaddrinfo(res); // Make the callback into JavaScript - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); delete req_wrap; } @@ -1025,7 +1025,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req, } // Make the callback into JavaScript - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); delete req_wrap; } diff --git a/src/debug-agent.cc b/src/debug-agent.cc index 93d2ce71f11a38..df6e75d07ff38c 100644 --- a/src/debug-agent.cc +++ b/src/debug-agent.cc @@ -22,7 +22,7 @@ #include "debug-agent.h" #include "node.h" -#include "node_internals.h" // ARRAY_SIZE +#include "node_internals.h" // arraysize #include "env.h" #include "env-inl.h" #include "v8.h" @@ -175,9 +175,9 @@ void Agent::WorkerRun() { isolate, &child_loop_, context, - ARRAY_SIZE(argv), + arraysize(argv), argv, - ARRAY_SIZE(argv), + arraysize(argv), argv); child_env_ = env; @@ -301,7 +301,7 @@ void Agent::ChildSignalCb(uv_async_t* signal) { MakeCallback(isolate, api, "onmessage", - ARRAY_SIZE(argv), + arraysize(argv), argv); delete msg; } diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 7768f94459c16a..a9f96389121c9e 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -159,7 +159,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, argv[2] = OneByteString(env->isolate(), filename); } - wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv); + wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv); } diff --git a/src/js_stream.cc b/src/js_stream.cc index 25938f111ba6ac..e81709a8056965 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -75,7 +75,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) { req_wrap->Dispatched(); Local res = - MakeCallback(env()->onshutdown_string(), ARRAY_SIZE(argv), argv); + MakeCallback(env()->onshutdown_string(), arraysize(argv), argv); return res->Int32Value(); } @@ -103,7 +103,7 @@ int JSStream::DoWrite(WriteWrap* w, w->Dispatched(); Local res = - MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv); + MakeCallback(env()->onwrite_string(), arraysize(argv), argv); return res->Int32Value(); } diff --git a/src/node.cc b/src/node.cc index ae2da15389f6f9..e5a62c6bc37035 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1113,7 +1113,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) { Local args[] = { event, promise, value }; Local process = env->process_object(); - callback->Call(process, ARRAY_SIZE(args), args); + callback->Call(process, arraysize(args), args); } void SetupPromises(const FunctionCallbackInfo& args) { @@ -1196,7 +1196,7 @@ Local MakeCallback(Environment* env, { Undefined(env->isolate()).As(), did_throw }; TryCatch try_catch(env->isolate()); MaybeLocal ar = - post_fn->Call(env->context(), object, ARRAY_SIZE(vals), vals); + post_fn->Call(env->context(), object, arraysize(vals), vals); if (ar.IsEmpty()) { ClearFatalExceptionHandlers(env); FatalException(env->isolate(), try_catch); @@ -1651,7 +1651,7 @@ static void GetActiveRequests(const FunctionCallbackInfo& args) { if (w->persistent().IsEmpty()) continue; argv[idx] = w->object(); - if (++idx >= ARRAY_SIZE(argv)) { + if (++idx >= arraysize(argv)) { fn->Call(ctx, ary, idx, argv).ToLocalChecked(); idx = 0; } @@ -1686,7 +1686,7 @@ void GetActiveHandles(const FunctionCallbackInfo& args) { if (owner->IsUndefined()) owner = object; argv[idx] = owner; - if (++idx >= ARRAY_SIZE(argv)) { + if (++idx >= arraysize(argv)) { fn->Call(ctx, ary, idx, argv).ToLocalChecked(); idx = 0; } @@ -2520,12 +2520,12 @@ static void EnvGetter(Local property, WCHAR buffer[32767]; // The maximum size allowed for environment variables. DWORD result = GetEnvironmentVariableW(reinterpret_cast(*key), buffer, - ARRAY_SIZE(buffer)); + arraysize(buffer)); // If result >= sizeof buffer the buffer was too small. That should never // happen. If result == 0 and result != ERROR_SUCCESS the variable was not // not found. if ((result > 0 || GetLastError() == ERROR_SUCCESS) && - result < ARRAY_SIZE(buffer)) { + result < arraysize(buffer)) { const uint16_t* two_byte_buffer = reinterpret_cast(buffer); Local rc = String::NewFromTwoByte(isolate, two_byte_buffer); return info.GetReturnValue().Set(rc); @@ -2626,7 +2626,7 @@ static void EnvEnumerator(const PropertyCallbackInfo& info) { var, String::kNormalString, length); - if (++idx >= ARRAY_SIZE(argv)) { + if (++idx >= arraysize(argv)) { fn->Call(ctx, envarr, idx, argv).ToLocalChecked(); idx = 0; } @@ -2658,7 +2658,7 @@ static void EnvEnumerator(const PropertyCallbackInfo& info) { two_byte_buffer, String::kNormalString, two_byte_buffer_len); - if (++idx >= ARRAY_SIZE(argv)) { + if (++idx >= arraysize(argv)) { fn->Call(ctx, envarr, idx, argv).ToLocalChecked(); idx = 0; } @@ -3556,7 +3556,7 @@ static void EnableDebug(Environment* env) { FIXED_ONE_BYTE_STRING(env->isolate(), "internalMessage"), message }; - MakeCallback(env, env->process_object(), "emit", ARRAY_SIZE(argv), argv); + MakeCallback(env, env->process_object(), "emit", arraysize(argv), argv); // Enabled debugger, possibly making it wait on a semaphore env->debugger_agent()->Enable(); @@ -3677,7 +3677,7 @@ static int RegisterDebugSignalHandler() { if (GetDebugSignalHandlerMappingName(pid, mapping_name, - ARRAY_SIZE(mapping_name)) < 0) { + arraysize(mapping_name)) < 0) { return -1; } @@ -3740,7 +3740,7 @@ static void DebugProcess(const FunctionCallbackInfo& args) { if (GetDebugSignalHandlerMappingName(pid, mapping_name, - ARRAY_SIZE(mapping_name)) < 0) { + arraysize(mapping_name)) < 0) { env->ThrowErrnoException(errno, "sprintf"); goto out; } @@ -4017,7 +4017,7 @@ void EmitBeforeExit(Environment* env) { FIXED_ONE_BYTE_STRING(env->isolate(), "beforeExit"), process_object->Get(exit_code)->ToInteger(env->isolate()) }; - MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); + MakeCallback(env, process_object, "emit", arraysize(args), args); } @@ -4036,7 +4036,7 @@ int EmitExit(Environment* env) { Integer::New(env->isolate(), code) }; - MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args); + MakeCallback(env, process_object, "emit", arraysize(args), args); // Reload exit code, it may be changed by `emit('exit')` return process_object->Get(exitCode)->Int32Value(); diff --git a/src/node_contextify.cc b/src/node_contextify.cc index ee175fa9c29f6f..1f2e73dc36cd16 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -163,7 +163,7 @@ class ContextifyContext { CHECK(clone_property_method->IsFunction()); } Local args[] = { global, key, sandbox_obj }; - clone_property_method->Call(global, ARRAY_SIZE(args), args); + clone_property_method->Call(global, arraysize(args), args); } } } diff --git a/src/node_counters.cc b/src/node_counters.cc index ca05e253199af5..9853784e557136 100644 --- a/src/node_counters.cc +++ b/src/node_counters.cc @@ -98,7 +98,7 @@ void InitPerfCounters(Environment* env, Local target) { #undef NODE_PROBE }; - for (int i = 0; i < ARRAY_SIZE(tab); i++) { + for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); target->Set(key, val); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index acd83e9f2f41ad..989110c9a9b4e3 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -752,7 +752,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { if (!root_cert_store) { root_cert_store = X509_STORE_new(); - for (size_t i = 0; i < ARRAY_SIZE(root_certs); i++) { + for (size_t i = 0; i < arraysize(root_certs); i++) { BIO* bp = NodeBIO::NewFixed(root_certs[i], strlen(root_certs[i])); if (bp == nullptr) { return; @@ -1084,7 +1084,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl, Local ret = node::MakeCallback(env, sc->object(), env->ticketkeycallback_string(), - ARRAY_SIZE(argv), + arraysize(argv), argv); Local arr = ret.As(); @@ -1281,7 +1281,7 @@ int SSLWrap::NewSessionCallback(SSL* s, SSL_SESSION* sess) { sess->session_id_length).ToLocalChecked(); Local argv[] = { session, buff }; w->new_session_wait_ = true; - w->MakeCallback(env->onnewsession_string(), ARRAY_SIZE(argv), argv); + w->MakeCallback(env->onnewsession_string(), arraysize(argv), argv); return 0; } @@ -1315,7 +1315,7 @@ void SSLWrap::OnClientHello(void* arg, Boolean::New(env->isolate(), hello.ocsp_request())); Local argv[] = { hello_obj }; - w->MakeCallback(env->onclienthello_string(), ARRAY_SIZE(argv), argv); + w->MakeCallback(env->onclienthello_string(), arraysize(argv), argv); } @@ -1390,8 +1390,8 @@ static Local X509ToObject(Environment* env, X509* cert) { int nids[] = { NID_subject_alt_name, NID_info_access }; Local keys[] = { env->subjectaltname_string(), env->infoaccess_string() }; - CHECK_EQ(ARRAY_SIZE(nids), ARRAY_SIZE(keys)); - for (unsigned int i = 0; i < ARRAY_SIZE(nids); i++) { + CHECK_EQ(arraysize(nids), arraysize(keys)); + for (size_t i = 0; i < arraysize(nids); i++) { int index = X509_get_ext_by_NID(cert, nids[i], -1); if (index < 0) continue; @@ -2282,7 +2282,7 @@ int SSLWrap::SSLCertCallback(SSL* s, void* arg) { info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp)); Local argv[] = { info }; - w->MakeCallback(env->oncertcb_string(), ARRAY_SIZE(argv), argv); + w->MakeCallback(env->oncertcb_string(), arraysize(argv), argv); if (!w->cert_cb_running_) return 1; @@ -2645,7 +2645,7 @@ inline CheckResult CheckWhitelistedServerCert(X509_STORE_CTX* ctx) { CHECK(ret); void* result = bsearch(hash, WhitelistedCNNICHashes, - ARRAY_SIZE(WhitelistedCNNICHashes), + arraysize(WhitelistedCNNICHashes), CNNIC_WHITELIST_HASH_LEN, compar); if (result == nullptr) { sk_X509_pop_free(chain, X509_free); @@ -4383,7 +4383,7 @@ void DiffieHellman::DiffieHellmanGroup( bool initialized = false; const node::Utf8Value group_name(env->isolate(), args[0]); - for (unsigned int i = 0; i < ARRAY_SIZE(modp_groups); ++i) { + for (size_t i = 0; i < arraysize(modp_groups); ++i) { const modp_group* it = modp_groups + i; if (strcasecmp(*group_name, it->name) != 0) @@ -5086,7 +5086,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) { Context::Scope context_scope(env->context()); Local argv[2]; EIO_PBKDF2After(req, argv); - req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv); + req->MakeCallback(env->ondone_string(), arraysize(argv), argv); delete req; } @@ -5327,7 +5327,7 @@ void RandomBytesAfter(uv_work_t* work_req, int status) { Context::Scope context_scope(env->context()); Local argv[2]; RandomBytesCheck(req, argv); - req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv); + req->MakeCallback(env->ondone_string(), arraysize(argv), argv); delete req; } diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 568972bab3f90f..b92a0dd411b981 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -257,7 +257,7 @@ void InitDTrace(Environment* env, Local target) { #undef NODE_PROBE }; - for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { + for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); target->Set(key, val); diff --git a/src/node_file.cc b/src/node_file.cc index 3fbec265663910..862edb8561e9e1 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -240,7 +240,7 @@ static void After(uv_fs_t *req) { name_argv[name_idx++] = String::NewFromUtf8(env->isolate(), ent.name); - if (name_idx >= ARRAY_SIZE(name_argv)) { + if (name_idx >= arraysize(name_argv)) { fn->Call(env->context(), names, name_idx, name_argv) .ToLocalChecked(); name_idx = 0; @@ -447,7 +447,7 @@ Local BuildStatsObject(Environment* env, const uv_stat_t* s) { // Call out to JavaScript to create the stats object. Local stats = - env->fs_stats_constructor_function()->NewInstance(ARRAY_SIZE(argv), argv); + env->fs_stats_constructor_function()->NewInstance(arraysize(argv), argv); if (stats.IsEmpty()) return handle_scope.Escape(Local()); @@ -845,7 +845,7 @@ static void ReadDir(const FunctionCallbackInfo& args) { name_v[name_idx++] = String::NewFromUtf8(env->isolate(), ent.name); - if (name_idx >= ARRAY_SIZE(name_v)) { + if (name_idx >= arraysize(name_v)) { fn->Call(env->context(), names, name_idx, name_v) .ToLocalChecked(); name_idx = 0; @@ -962,7 +962,7 @@ static void WriteBuffers(const FunctionCallbackInfo& args) { uv_buf_t s_iovs[1024]; // use stack allocation when possible uv_buf_t* iovs; - if (chunkCount > ARRAY_SIZE(s_iovs)) + if (chunkCount > arraysize(s_iovs)) iovs = new uv_buf_t[chunkCount]; else iovs = s_iovs; diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 12ae9e1443f534..a9081dc674808f 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -193,7 +193,7 @@ class Parser : public AsyncWrap { if (num_fields_ == num_values_) { // start of new field name num_fields_++; - if (num_fields_ == ARRAY_SIZE(fields_)) { + if (num_fields_ == static_cast(arraysize(fields_))) { // ran out of space - flush to javascript land Flush(); num_fields_ = 1; @@ -202,7 +202,7 @@ class Parser : public AsyncWrap { fields_[num_fields_ - 1].Reset(); } - CHECK_LT(num_fields_, static_cast(ARRAY_SIZE(fields_))); + CHECK_LT(num_fields_, static_cast(arraysize(fields_))); CHECK_EQ(num_fields_, num_values_ + 1); fields_[num_fields_ - 1].Update(at, length); @@ -218,7 +218,7 @@ class Parser : public AsyncWrap { values_[num_values_ - 1].Reset(); } - CHECK_LT(num_values_, static_cast(ARRAY_SIZE(values_))); + CHECK_LT(num_values_, static_cast(arraysize(values_))); CHECK_EQ(num_values_, num_fields_); values_[num_values_ - 1].Update(at, length); @@ -252,7 +252,7 @@ class Parser : public AsyncWrap { return 0; Local undefined = Undefined(env()->isolate()); - for (size_t i = 0; i < ARRAY_SIZE(argv); i++) + for (size_t i = 0; i < arraysize(argv); i++) argv[i] = undefined; if (have_flushed_) { @@ -293,7 +293,7 @@ class Parser : public AsyncWrap { Environment::AsyncCallbackScope callback_scope(env()); Local head_response = - MakeCallback(cb.As(), ARRAY_SIZE(argv), argv); + MakeCallback(cb.As(), arraysize(argv), argv); if (head_response.IsEmpty()) { got_exception_ = true; @@ -328,7 +328,7 @@ class Parser : public AsyncWrap { Integer::NewFromUnsigned(env()->isolate(), length) }; - Local r = MakeCallback(cb.As(), ARRAY_SIZE(argv), argv); + Local r = MakeCallback(cb.As(), arraysize(argv), argv); if (r.IsEmpty()) { got_exception_ = true; @@ -646,7 +646,7 @@ class Parser : public AsyncWrap { do { size_t j = 0; - while (i < num_values_ && j < ARRAY_SIZE(argv) / 2) { + while (i < num_values_ && j < arraysize(argv) / 2) { argv[j * 2] = fields_[i].ToString(env()); argv[j * 2 + 1] = values_[i].ToString(env()); i++; @@ -676,7 +676,7 @@ class Parser : public AsyncWrap { url_.ToString(env()) }; - Local r = MakeCallback(cb.As(), ARRAY_SIZE(argv), argv); + Local r = MakeCallback(cb.As(), arraysize(argv), argv); if (r.IsEmpty()) got_exception_ = true; diff --git a/src/node_internals.h b/src/node_internals.h index 0523a3f8bc0a6b..e17f6ca2e47f37 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -107,8 +107,11 @@ inline static int snprintf(char *buffer, size_t n, const char *format, ...) { #endif #endif -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define arraysize(a) (sizeof(a) / sizeof(*a)) // Workaround for VS 2013. +#else +template +constexpr size_t arraysize(const T(&)[N]) { return N; } #endif #ifndef ROUND_UP diff --git a/src/node_lttng.cc b/src/node_lttng.cc index 876bcda92f82fa..41ccdf33411563 100644 --- a/src/node_lttng.cc +++ b/src/node_lttng.cc @@ -250,7 +250,7 @@ void InitLTTNG(Environment* env, Local target) { #undef NODE_PROBE }; - for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { + for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); target->Set(key, val); diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index bd1cb73248e99c..4fa01794f6c6da 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -70,7 +70,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle, BuildStatsObject(env, prev), Integer::New(env->isolate(), status) }; - wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv); + wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv); } diff --git a/src/node_win32_etw_provider-inl.h b/src/node_win32_etw_provider-inl.h index 3fef20cc1488c1..04cd31cee3c2f6 100644 --- a/src/node_win32_etw_provider-inl.h +++ b/src/node_win32_etw_provider-inl.h @@ -202,7 +202,7 @@ void NODE_V8SYMBOL_RESET() { #define SETSYMBUF(s) \ wcscpy(symbuf, s); \ - symbol_len = ARRAY_SIZE(s) - 1; + symbol_len = arraysize(s) - 1; void NODE_V8SYMBOL_ADD(LPCSTR symbol, int symbol_len, diff --git a/src/node_win32_etw_provider.cc b/src/node_win32_etw_provider.cc index c6bfbeaaf6c989..6877f1977dae8b 100644 --- a/src/node_win32_etw_provider.cc +++ b/src/node_win32_etw_provider.cc @@ -56,7 +56,7 @@ struct v8tags trace_codes[] = { // If prefix is not in filtered list return -1, // else return length of prefix and marker. int FilterCodeEvents(const char* name, size_t len) { - for (int i = 0; i < ARRAY_SIZE(trace_codes); i++) { + for (size_t i = 0; i < arraysize(trace_codes); i++) { size_t prelen = trace_codes[i].prelen; if (prelen < len) { if (strncmp(name, trace_codes[i].prefix, prelen) == 0) { diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 0712f8feec6f08..c8ef8f3f863d01 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -334,7 +334,7 @@ class ZCtx : public AsyncWrap { // call the write() cb Local args[2] = { avail_in, avail_out }; - ctx->MakeCallback(env->callback_string(), ARRAY_SIZE(args), args); + ctx->MakeCallback(env->callback_string(), arraysize(args), args); ctx->Unref(); if (ctx->pending_close_) @@ -356,7 +356,7 @@ class ZCtx : public AsyncWrap { OneByteString(env->isolate(), message), Number::New(env->isolate(), ctx->err_) }; - ctx->MakeCallback(env->onerror_string(), ARRAY_SIZE(args), args); + ctx->MakeCallback(env->onerror_string(), arraysize(args), args); // no hope of rescue. if (ctx->write_in_progress_) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 84164723e95b99..e3377d402f5ab1 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -183,7 +183,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { }; if (status != 0) { - pipe_wrap->MakeCallback(env->onconnection_string(), ARRAY_SIZE(argv), argv); + pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv); return; } @@ -198,7 +198,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) { // Successful accept. Call the onconnection callback in JavaScript land. argv[1] = client_obj; - pipe_wrap->MakeCallback(env->onconnection_string(), ARRAY_SIZE(argv), argv); + pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv); } // TODO(bnoordhuis) Maybe share this with TCPWrap? @@ -233,7 +233,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { Boolean::New(env->isolate(), writable) }; - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); delete req_wrap; } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index adf1606591f156..7e9d2070bb9b7c 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -252,7 +252,7 @@ class ProcessWrap : public HandleWrap { OneByteString(env->isolate(), signo_string(term_signal)) }; - wrap->MakeCallback(env->onexit_string(), ARRAY_SIZE(argv), argv); + wrap->MakeCallback(env->onexit_string(), arraysize(argv), argv); } uv_process_t process_; diff --git a/src/stream_base.cc b/src/stream_base.cc index 27ae0fee7b1309..f9fed08d134c50 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -83,7 +83,7 @@ void StreamBase::AfterShutdown(ShutdownWrap* req_wrap, int status) { }; if (req_wrap->object()->Has(env->oncomplete_string())) - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); delete req_wrap; } @@ -130,7 +130,7 @@ int StreamBase::Writev(const FunctionCallbackInfo& args) { if (storage_size > INT_MAX) return UV_ENOBUFS; - if (ARRAY_SIZE(bufs_) < count) + if (arraysize(bufs_) < count) bufs = new uv_buf_t[count]; WriteWrap* req_wrap = WriteWrap::New(env, @@ -388,7 +388,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) { } if (req_wrap->object()->Has(env->oncomplete_string())) - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); req_wrap->Dispose(); } @@ -416,10 +416,10 @@ void StreamBase::EmitData(ssize_t nread, node::MakeCallback(env, GetObject(), env->onread_string(), - ARRAY_SIZE(argv), + arraysize(argv), argv); } else { - async->MakeCallback(env->onread_string(), ARRAY_SIZE(argv), argv); + async->MakeCallback(env->onread_string(), arraysize(argv), argv); } } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 3f3e6a0ad4a752..0214be100228c4 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -269,7 +269,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) { argv[1] = client_obj; } - tcp_wrap->MakeCallback(env->onconnection_string(), ARRAY_SIZE(argv), argv); + tcp_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv); } @@ -295,7 +295,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) { v8::True(env->isolate()) }; - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); delete req_wrap; } diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 85730b34936b55..48ec8a54a98c79 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -283,8 +283,8 @@ void TLSWrap::EncOut() { } char* data[kSimultaneousBufferCount]; - size_t size[ARRAY_SIZE(data)]; - size_t count = ARRAY_SIZE(data); + size_t size[arraysize(data)]; + size_t count = arraysize(data); write_size_ = NodeBIO::FromBIO(enc_out_)->PeekMultiple(data, size, &count); CHECK(write_size_ != 0 && count != 0); @@ -295,7 +295,7 @@ void TLSWrap::EncOut() { this, EncOutCb); - uv_buf_t buf[ARRAY_SIZE(data)]; + uv_buf_t buf[arraysize(data)]; for (size_t i = 0; i < count; i++) buf[i] = uv_buf_init(data[i], size[i]); int err = stream_->DoWrite(write_req, buf, count, nullptr); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index 1faf45a95daf33..955d3a1e16042b 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -270,7 +270,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo& args, int family) { uv_buf_t bufs_[16]; uv_buf_t* bufs = bufs_; - if (ARRAY_SIZE(bufs_) < count) + if (arraysize(bufs_) < count) bufs = new uv_buf_t[count]; // construct uv_buf_t array @@ -406,14 +406,14 @@ void UDPWrap::OnRecv(uv_udp_t* handle, if (nread < 0) { if (buf->base != nullptr) free(buf->base); - wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv); + wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv); return; } char* base = static_cast(realloc(buf->base, nread)); argv[2] = Buffer::New(env, base, nread).ToLocalChecked(); argv[3] = AddressToJS(env, addr); - wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv); + wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv); }