Skip to content
Closed
Changes from 1 commit
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
17 changes: 10 additions & 7 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void cares_wrap_hostent_cpy(struct hostent* dest, struct hostent* src) {

/* copy `h_name` */
size_t name_size = strlen(src->h_name) + 1;
dest->h_name = node::Malloc<char>(name_size);
dest->h_name = reinterpret_cast<char*>(node::Malloc(name_size));
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid reinterpret_cast when a static_cast does the job just fine? Alternatively, you could also backport the overloads of node::Malloc & similar methods as they are on master, that would help with backporting other patches in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@addaleax #8482 it shows dont-land-on-v6.x and v4.x. May I still make a backport for it?

Copy link
Member

Choose a reason for hiding this comment

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

@XadillaX Yes, you’ll just need to try and see how to resolve the conflicts that you’re going to get. I suspect that will be a bit of work, so only do that if you have the time; for now, just changing to static_cast here is definitely easier. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@addaleax I found a backport chain for #8482, it will be a big backport. So I decide to only backport this PR but not #8482 and its dependencies.

memcpy(dest->h_name, src->h_name, name_size);

/* copy `h_aliases` */
Expand All @@ -329,10 +329,12 @@ void cares_wrap_hostent_cpy(struct hostent* dest, struct hostent* src) {
alias_count++) {
}

dest->h_aliases = node::Malloc<char*>(alias_count + 1);
dest->h_aliases = reinterpret_cast<char**>(node::Malloc((alias_count + 1) *
sizeof(char*)));
for (size_t i = 0; i < alias_count; i++) {
cur_alias_length = strlen(src->h_aliases[i]);
dest->h_aliases[i] = node::Malloc(cur_alias_length + 1);
dest->h_aliases[i] = reinterpret_cast<char*>(node::Malloc(cur_alias_length +
1));
memcpy(dest->h_aliases[i], src->h_aliases[i], cur_alias_length + 1);
}
dest->h_aliases[alias_count] = nullptr;
Expand All @@ -344,9 +346,10 @@ void cares_wrap_hostent_cpy(struct hostent* dest, struct hostent* src) {
list_count++) {
}

dest->h_addr_list = node::Malloc<char*>(list_count + 1);
dest->h_addr_list = reinterpret_cast<char**>(node::Malloc((list_count + 1) *
sizeof(char*)));
for (size_t i = 0; i < list_count; i++) {
dest->h_addr_list[i] = node::Malloc(src->h_length);
dest->h_addr_list[i] = reinterpret_cast<char*>(node::Malloc(src->h_length));
memcpy(dest->h_addr_list[i], src->h_addr_list[i], src->h_length);
}
dest->h_addr_list[list_count] = nullptr;
Expand Down Expand Up @@ -435,7 +438,7 @@ class QueryWrap : public AsyncWrap {

unsigned char* buf_copy = nullptr;
if (status == ARES_SUCCESS) {
buf_copy = node::Malloc<unsigned char>(answer_len);
buf_copy = reinterpret_cast<unsigned char*>(node::Malloc(answer_len));
memcpy(buf_copy, answer_buf, answer_len);
}

Expand All @@ -459,7 +462,7 @@ class QueryWrap : public AsyncWrap {

struct hostent* host_copy = nullptr;
if (status == ARES_SUCCESS) {
host_copy = node::Malloc<hostent>(1);
host_copy = reinterpret_cast<hostent*>(node::Malloc(sizeof(hostent)));
cares_wrap_hostent_cpy(host_copy, host);
}

Expand Down