Skip to content

Commit

Permalink
src: reduce variable scope in cares_wrap.cc
Browse files Browse the repository at this point in the history
PR-URL: #23297
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and targos committed Oct 10, 2018
1 parent 9dd47bc commit 402867c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,17 +429,16 @@ void cares_wrap_hostent_cpy(struct hostent* dest, struct hostent* src) {

/* copy `h_aliases` */
size_t alias_count;
size_t cur_alias_length;
for (alias_count = 0;
src->h_aliases[alias_count] != nullptr;
alias_count++) {
}

dest->h_aliases = node::Malloc<char*>(alias_count + 1);
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);
memcpy(dest->h_aliases[i], src->h_aliases[i], cur_alias_length + 1);
const size_t cur_alias_size = strlen(src->h_aliases[i]) + 1;
dest->h_aliases[i] = node::Malloc(cur_alias_size);
memcpy(dest->h_aliases[i], src->h_aliases[i], cur_alias_size);
}
dest->h_aliases[alias_count] = nullptr;

Expand Down Expand Up @@ -1065,7 +1064,6 @@ int ParseSoaReply(Environment* env,
/* Can't use ares_parse_soa_reply() here which can only parse single record */
unsigned int ancount = cares_get_16bit(buf + 6);
unsigned char* ptr = buf + NS_HFIXEDSZ;
int rr_type, rr_len;
char* name;
char* rr_name;
long temp_len; // NOLINT(runtime/int)
Expand Down Expand Up @@ -1094,8 +1092,8 @@ int ParseSoaReply(Environment* env,
break;
}

rr_type = cares_get_16bit(ptr);
rr_len = cares_get_16bit(ptr + 8);
const int rr_type = cares_get_16bit(ptr);
const int rr_len = cares_get_16bit(ptr + 8);
ptr += NS_RRFIXEDSZ;

/* only need SOA */
Expand Down

0 comments on commit 402867c

Please sign in to comment.