Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit af41a63

Browse filesBrowse files
bnoordhuisMyles Borins
authored andcommitted
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: #5969 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ab50e82 commit af41a63
Copy full SHA for af41a63
Expand file treeCollapse file tree

24 files changed

+70
-67
lines changed
Open diff view settings
Collapse file

‎src/async-wrap-inl.h‎

Copy file name to clipboardExpand all lines: src/async-wrap-inl.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
4949
argv[2] = parent->object();
5050

5151
v8::MaybeLocal<v8::Value> ret =
52-
init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv);
52+
init_fn->Call(env->context(), object, arraysize(argv), argv);
5353

5454
if (ret.IsEmpty())
5555
FatalError("node::AsyncWrap::AsyncWrap", "init hook threw");
Collapse file

‎src/cares_wrap.cc‎

Copy file name to clipboardExpand all lines: src/cares_wrap.cc
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class QueryWrap : public AsyncWrap {
310310
Integer::New(env()->isolate(), 0),
311311
answer
312312
};
313-
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
313+
MakeCallback(env()->oncomplete_string(), arraysize(argv), argv);
314314
}
315315

316316
void CallOnComplete(Local<Value> answer, Local<Value> family) {
@@ -321,7 +321,7 @@ class QueryWrap : public AsyncWrap {
321321
answer,
322322
family
323323
};
324-
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
324+
MakeCallback(env()->oncomplete_string(), arraysize(argv), argv);
325325
}
326326

327327
void ParseError(int status) {
@@ -994,7 +994,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
994994
uv_freeaddrinfo(res);
995995

996996
// Make the callback into JavaScript
997-
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
997+
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
998998

999999
delete req_wrap;
10001000
}
@@ -1025,7 +1025,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
10251025
}
10261026

10271027
// Make the callback into JavaScript
1028-
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
1028+
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
10291029

10301030
delete req_wrap;
10311031
}
Collapse file

‎src/debug-agent.cc‎

Copy file name to clipboardExpand all lines: src/debug-agent.cc
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "debug-agent.h"
2323

2424
#include "node.h"
25-
#include "node_internals.h" // ARRAY_SIZE
25+
#include "node_internals.h" // arraysize
2626
#include "env.h"
2727
#include "env-inl.h"
2828
#include "v8.h"
@@ -175,9 +175,9 @@ void Agent::WorkerRun() {
175175
isolate,
176176
&child_loop_,
177177
context,
178-
ARRAY_SIZE(argv),
178+
arraysize(argv),
179179
argv,
180-
ARRAY_SIZE(argv),
180+
arraysize(argv),
181181
argv);
182182

183183
child_env_ = env;
@@ -301,7 +301,7 @@ void Agent::ChildSignalCb(uv_async_t* signal) {
301301
MakeCallback(isolate,
302302
api,
303303
"onmessage",
304-
ARRAY_SIZE(argv),
304+
arraysize(argv),
305305
argv);
306306
delete msg;
307307
}
Collapse file

‎src/fs_event_wrap.cc‎

Copy file name to clipboardExpand all lines: src/fs_event_wrap.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
159159
argv[2] = OneByteString(env->isolate(), filename);
160160
}
161161

162-
wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv);
162+
wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv);
163163
}
164164

165165

Collapse file

‎src/js_stream.cc‎

Copy file name to clipboardExpand all lines: src/js_stream.cc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) {
7575

7676
req_wrap->Dispatched();
7777
Local<Value> res =
78-
MakeCallback(env()->onshutdown_string(), ARRAY_SIZE(argv), argv);
78+
MakeCallback(env()->onshutdown_string(), arraysize(argv), argv);
7979

8080
return res->Int32Value();
8181
}
@@ -103,7 +103,7 @@ int JSStream::DoWrite(WriteWrap* w,
103103

104104
w->Dispatched();
105105
Local<Value> res =
106-
MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv);
106+
MakeCallback(env()->onwrite_string(), arraysize(argv), argv);
107107

108108
return res->Int32Value();
109109
}
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
10971097
Local<Value> args[] = { event, promise, value };
10981098
Local<Object> process = env->process_object();
10991099

1100-
callback->Call(process, ARRAY_SIZE(args), args);
1100+
callback->Call(process, arraysize(args), args);
11011101
}
11021102

11031103
void SetupPromises(const FunctionCallbackInfo<Value>& args) {
@@ -2453,12 +2453,12 @@ static void EnvGetter(Local<String> property,
24532453
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
24542454
DWORD result = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(*key),
24552455
buffer,
2456-
ARRAY_SIZE(buffer));
2456+
arraysize(buffer));
24572457
// If result >= sizeof buffer the buffer was too small. That should never
24582458
// happen. If result == 0 and result != ERROR_SUCCESS the variable was not
24592459
// not found.
24602460
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
2461-
result < ARRAY_SIZE(buffer)) {
2461+
result < arraysize(buffer)) {
24622462
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
24632463
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
24642464
return info.GetReturnValue().Set(rc);
@@ -3457,7 +3457,7 @@ static void EnableDebug(Environment* env) {
34573457
FIXED_ONE_BYTE_STRING(env->isolate(), "internalMessage"),
34583458
message
34593459
};
3460-
MakeCallback(env, env->process_object(), "emit", ARRAY_SIZE(argv), argv);
3460+
MakeCallback(env, env->process_object(), "emit", arraysize(argv), argv);
34613461

34623462
// Enabled debugger, possibly making it wait on a semaphore
34633463
env->debugger_agent()->Enable();
@@ -3578,7 +3578,7 @@ static int RegisterDebugSignalHandler() {
35783578

35793579
if (GetDebugSignalHandlerMappingName(pid,
35803580
mapping_name,
3581-
ARRAY_SIZE(mapping_name)) < 0) {
3581+
arraysize(mapping_name)) < 0) {
35823582
return -1;
35833583
}
35843584

@@ -3641,7 +3641,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
36413641

36423642
if (GetDebugSignalHandlerMappingName(pid,
36433643
mapping_name,
3644-
ARRAY_SIZE(mapping_name)) < 0) {
3644+
arraysize(mapping_name)) < 0) {
36453645
env->ThrowErrnoException(errno, "sprintf");
36463646
goto out;
36473647
}
@@ -3918,7 +3918,7 @@ void EmitBeforeExit(Environment* env) {
39183918
FIXED_ONE_BYTE_STRING(env->isolate(), "beforeExit"),
39193919
process_object->Get(exit_code)->ToInteger(env->isolate())
39203920
};
3921-
MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
3921+
MakeCallback(env, process_object, "emit", arraysize(args), args);
39223922
}
39233923

39243924

@@ -3937,7 +3937,7 @@ int EmitExit(Environment* env) {
39373937
Integer::New(env->isolate(), code)
39383938
};
39393939

3940-
MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
3940+
MakeCallback(env, process_object, "emit", arraysize(args), args);
39413941

39423942
// Reload exit code, it may be changed by `emit('exit')`
39433943
return process_object->Get(exitCode)->Int32Value();
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class ContextifyContext {
161161
CHECK(clone_property_method->IsFunction());
162162
}
163163
Local<Value> args[] = { global, key, sandbox_obj };
164-
clone_property_method->Call(global, ARRAY_SIZE(args), args);
164+
clone_property_method->Call(global, arraysize(args), args);
165165
}
166166
}
167167
}
Collapse file

‎src/node_counters.cc‎

Copy file name to clipboardExpand all lines: src/node_counters.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void InitPerfCounters(Environment* env, Local<Object> target) {
9898
#undef NODE_PROBE
9999
};
100100

101-
for (int i = 0; i < ARRAY_SIZE(tab); i++) {
101+
for (size_t i = 0; i < arraysize(tab); i++) {
102102
Local<String> key = OneByteString(env->isolate(), tab[i].name);
103103
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
104104
target->Set(key, val);
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
760760
if (!root_cert_store) {
761761
root_cert_store = X509_STORE_new();
762762

763-
for (size_t i = 0; i < ARRAY_SIZE(root_certs); i++) {
763+
for (size_t i = 0; i < arraysize(root_certs); i++) {
764764
BIO* bp = NodeBIO::NewFixed(root_certs[i], strlen(root_certs[i]));
765765
if (bp == nullptr) {
766766
return;
@@ -1092,7 +1092,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
10921092
Local<Value> ret = node::MakeCallback(env,
10931093
sc->object(),
10941094
env->ticketkeycallback_string(),
1095-
ARRAY_SIZE(argv),
1095+
arraysize(argv),
10961096
argv);
10971097
Local<Array> arr = ret.As<Array>();
10981098

@@ -1284,7 +1284,7 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) {
12841284
sess->session_id_length).ToLocalChecked();
12851285
Local<Value> argv[] = { session, buff };
12861286
w->new_session_wait_ = true;
1287-
w->MakeCallback(env->onnewsession_string(), ARRAY_SIZE(argv), argv);
1287+
w->MakeCallback(env->onnewsession_string(), arraysize(argv), argv);
12881288

12891289
return 0;
12901290
}
@@ -1318,7 +1318,7 @@ void SSLWrap<Base>::OnClientHello(void* arg,
13181318
Boolean::New(env->isolate(), hello.ocsp_request()));
13191319

13201320
Local<Value> argv[] = { hello_obj };
1321-
w->MakeCallback(env->onclienthello_string(), ARRAY_SIZE(argv), argv);
1321+
w->MakeCallback(env->onclienthello_string(), arraysize(argv), argv);
13221322
}
13231323

13241324

@@ -1393,8 +1393,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
13931393
int nids[] = { NID_subject_alt_name, NID_info_access };
13941394
Local<String> keys[] = { env->subjectaltname_string(),
13951395
env->infoaccess_string() };
1396-
CHECK_EQ(ARRAY_SIZE(nids), ARRAY_SIZE(keys));
1397-
for (unsigned int i = 0; i < ARRAY_SIZE(nids); i++) {
1396+
CHECK_EQ(arraysize(nids), arraysize(keys));
1397+
for (size_t i = 0; i < arraysize(nids); i++) {
13981398
int index = X509_get_ext_by_NID(cert, nids[i], -1);
13991399
if (index < 0)
14001400
continue;
@@ -2128,7 +2128,7 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) {
21282128
info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp));
21292129

21302130
Local<Value> argv[] = { info };
2131-
w->MakeCallback(env->oncertcb_string(), ARRAY_SIZE(argv), argv);
2131+
w->MakeCallback(env->oncertcb_string(), arraysize(argv), argv);
21322132

21332133
if (!w->cert_cb_running_)
21342134
return 1;
@@ -2491,7 +2491,7 @@ inline CheckResult CheckWhitelistedServerCert(X509_STORE_CTX* ctx) {
24912491
CHECK(ret);
24922492

24932493
void* result = bsearch(hash, WhitelistedCNNICHashes,
2494-
ARRAY_SIZE(WhitelistedCNNICHashes),
2494+
arraysize(WhitelistedCNNICHashes),
24952495
CNNIC_WHITELIST_HASH_LEN, compar);
24962496
if (result == nullptr) {
24972497
sk_X509_pop_free(chain, X509_free);
@@ -4229,7 +4229,7 @@ void DiffieHellman::DiffieHellmanGroup(
42294229
bool initialized = false;
42304230

42314231
const node::Utf8Value group_name(env->isolate(), args[0]);
4232-
for (unsigned int i = 0; i < ARRAY_SIZE(modp_groups); ++i) {
4232+
for (size_t i = 0; i < arraysize(modp_groups); ++i) {
42334233
const modp_group* it = modp_groups + i;
42344234

42354235
if (strcasecmp(*group_name, it->name) != 0)
@@ -4883,7 +4883,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
48834883
Context::Scope context_scope(env->context());
48844884
Local<Value> argv[2];
48854885
EIO_PBKDF2After(req, argv);
4886-
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
4886+
req->MakeCallback(env->ondone_string(), arraysize(argv), argv);
48874887
delete req;
48884888
}
48894889

@@ -5124,7 +5124,7 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
51245124
Context::Scope context_scope(env->context());
51255125
Local<Value> argv[2];
51265126
RandomBytesCheck(req, argv);
5127-
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
5127+
req->MakeCallback(env->ondone_string(), arraysize(argv), argv);
51285128
delete req;
51295129
}
51305130

Collapse file

‎src/node_dtrace.cc‎

Copy file name to clipboardExpand all lines: src/node_dtrace.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void InitDTrace(Environment* env, Local<Object> target) {
257257
#undef NODE_PROBE
258258
};
259259

260-
for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) {
260+
for (size_t i = 0; i < arraysize(tab); i++) {
261261
Local<String> key = OneByteString(env->isolate(), tab[i].name);
262262
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
263263
target->Set(key, val);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.