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: fix ARRAY_SIZE() logic error #5969

Merged
merged 3 commits into from
Apr 5, 2016
Merged
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
2 changes: 1 addition & 1 deletion src/async-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
v8::TryCatch try_catch(env->isolate());

v8::MaybeLocal<v8::Value> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
Local<Value> vals[] = { uid, did_throw };
TryCatch try_catch(env()->isolate());
MaybeLocal<Value> 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);
Expand Down
8 changes: 4 additions & 4 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> answer, Local<Value> family) {
Expand All @@ -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) {
Expand Down Expand Up @@ -1037,7 +1037,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;
}
Expand Down Expand Up @@ -1068,7 +1068,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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/debug-agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -176,9 +176,9 @@ void Agent::WorkerRun() {
isolate,
&child_loop_,
context,
ARRAY_SIZE(argv),
arraysize(argv),
argv,
ARRAY_SIZE(argv),
arraysize(argv),
argv);

child_env_ = env;
Expand Down Expand Up @@ -303,7 +303,7 @@ void Agent::ChildSignalCb(uv_async_t* signal) {
MakeCallback(isolate,
api,
"onmessage",
ARRAY_SIZE(argv),
arraysize(argv),
argv);
delete msg;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
}
}

wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv);
wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv);
}


Expand Down
4 changes: 2 additions & 2 deletions src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) {

req_wrap->Dispatched();
Local<Value> res =
MakeCallback(env()->onshutdown_string(), ARRAY_SIZE(argv), argv);
MakeCallback(env()->onshutdown_string(), arraysize(argv), argv);

return res->Int32Value();
}
Expand Down Expand Up @@ -103,7 +103,7 @@ int JSStream::DoWrite(WriteWrap* w,

w->Dispatched();
Local<Value> res =
MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv);
MakeCallback(env()->onwrite_string(), arraysize(argv), argv);

return res->Int32Value();
}
Expand Down
28 changes: 14 additions & 14 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
Local<Value> args[] = { event, promise, value };
Local<Object> process = env->process_object();

callback->Call(process, ARRAY_SIZE(args), args);
callback->Call(process, arraysize(args), args);
}

void SetupPromises(const FunctionCallbackInfo<Value>& args) {
Expand Down Expand Up @@ -1213,7 +1213,7 @@ Local<Value> MakeCallback(Environment* env,
{ Undefined(env->isolate()).As<Value>(), did_throw };
TryCatch try_catch(env->isolate());
MaybeLocal<Value> 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);
Expand Down Expand Up @@ -1691,7 +1691,7 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& 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;
}
Expand Down Expand Up @@ -1726,7 +1726,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& 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;
}
Expand Down Expand Up @@ -2564,12 +2564,12 @@ static void EnvGetter(Local<String> property,
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
DWORD result = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(*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<const uint16_t*>(buffer);
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
return info.GetReturnValue().Set(rc);
Expand Down Expand Up @@ -2670,7 +2670,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
var,
String::kNormalString,
length);
if (++idx >= ARRAY_SIZE(argv)) {
if (++idx >= arraysize(argv)) {
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
idx = 0;
}
Expand Down Expand Up @@ -2702,7 +2702,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& 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;
}
Expand Down Expand Up @@ -3327,7 +3327,7 @@ void LoadEnvironment(Environment* env) {
global->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global);

Local<Value> arg = env->process_object();
f->Call(Null(env->isolate()), ARRAY_SIZE(&arg), &arg);
f->Call(Null(env->isolate()), 1, &arg);
}

static void PrintHelp();
Expand Down Expand Up @@ -3641,7 +3641,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();
Expand Down Expand Up @@ -3762,7 +3762,7 @@ static int RegisterDebugSignalHandler() {

if (GetDebugSignalHandlerMappingName(pid,
mapping_name,
ARRAY_SIZE(mapping_name)) < 0) {
arraysize(mapping_name)) < 0) {
return -1;
}

Expand Down Expand Up @@ -3825,7 +3825,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {

if (GetDebugSignalHandlerMappingName(pid,
mapping_name,
ARRAY_SIZE(mapping_name)) < 0) {
arraysize(mapping_name)) < 0) {
env->ThrowErrnoException(errno, "sprintf");
goto out;
}
Expand Down Expand Up @@ -4102,7 +4102,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);
}


Expand All @@ -4121,7 +4121,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();
Expand Down
2 changes: 1 addition & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class ContextifyContext {
CHECK(clone_property_method->IsFunction());
}
Local<Value> args[] = { global, key, sandbox_obj };
clone_property_method->Call(global, ARRAY_SIZE(args), args);
clone_property_method->Call(global, arraysize(args), args);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/node_counters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void InitPerfCounters(Environment* env, Local<Object> target) {
#undef NODE_PROBE
};

for (int i = 0; i < ARRAY_SIZE(tab); i++) {
for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
target->Set(key, val);
Expand Down
22 changes: 11 additions & 11 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& 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;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
Local<Value> ret = node::MakeCallback(env,
sc->object(),
env->ticketkeycallback_string(),
ARRAY_SIZE(argv),
arraysize(argv),
argv);
Local<Array> arr = ret.As<Array>();

Expand Down Expand Up @@ -1307,7 +1307,7 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) {
sess->session_id_length).ToLocalChecked();
Local<Value> 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;
}
Expand Down Expand Up @@ -1341,7 +1341,7 @@ void SSLWrap<Base>::OnClientHello(void* arg,
Boolean::New(env->isolate(), hello.ocsp_request()));

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


Expand Down Expand Up @@ -1416,8 +1416,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
int nids[] = { NID_subject_alt_name, NID_info_access };
Local<String> 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;
Expand Down Expand Up @@ -2326,7 +2326,7 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) {
info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp));

Local<Value> 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;
Expand Down Expand Up @@ -2689,7 +2689,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);
Expand Down Expand Up @@ -4438,7 +4438,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)
Expand Down Expand Up @@ -5141,7 +5141,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
Context::Scope context_scope(env->context());
Local<Value> 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;
}

Expand Down Expand Up @@ -5382,7 +5382,7 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
Context::Scope context_scope(env->context());
Local<Value> argv[2];
RandomBytesCheck(req, argv);
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
req->MakeCallback(env->ondone_string(), arraysize(argv), argv);
delete req;
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_dtrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void InitDTrace(Environment* env, Local<Object> target) {
#undef NODE_PROBE
};

for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) {
for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
target->Set(key, val);
Expand Down
8 changes: 4 additions & 4 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void After(uv_fs_t *req) {
}
name_argv[name_idx++] = filename;

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;
Expand Down Expand Up @@ -491,7 +491,7 @@ Local<Value> BuildStatsObject(Environment* env, const uv_stat_t* s) {
Local<Value> stats =
env->fs_stats_constructor_function()->NewInstance(
env->context(),
ARRAY_SIZE(argv),
arraysize(argv),
argv).FromMaybe(Local<Value>());

if (stats.IsEmpty())
Expand Down Expand Up @@ -913,7 +913,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {

name_v[name_idx++] = filename;

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;
Expand Down Expand Up @@ -1030,7 +1030,7 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& 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;
Expand Down
Loading