Skip to content
Closed
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/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum url_update_action {
kHref = 9,
};

void SetArgs(Environment* env, Local<Value> argv[12], const ada::result& url) {
void SetArgs(Environment* env, Local<Value> argv[13], const ada::result& url) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array arguments decay to pointers so this, in the abstract, doesn't fix anything. You could change it to:

Suggested change
void SetArgs(Environment* env, Local<Value> argv[13], const ada::result& url) {
void SetArgs(Environment* env, Local<Value> (*argv)[13], const ada::result& url) {

That forces callers to pass a 13-element array by address, i.e.:

Local<Value> argv[13];
SetArgs(env, &argv, url);

You'll need to update all the assignments from argv[0] to (*argv)[0].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For education purposes: How did the code work before this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wrote past the end. Array arguments aren't length-checked; to the compiler int x[42] equals int x[] equals int *x.

Isolate* isolate = env->isolate();
argv[0] = Utf8String(isolate, url->get_href());
argv[1] = Utf8String(isolate, url->get_origin());
Expand Down