Skip to content

Commit 402867c

Browse files
cjihrigtargos
authored andcommitted
src: reduce variable scope in cares_wrap.cc
PR-URL: #23297 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 9dd47bc commit 402867c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/cares_wrap.cc

+5-7
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,16 @@ void cares_wrap_hostent_cpy(struct hostent* dest, struct hostent* src) {
429429

430430
/* copy `h_aliases` */
431431
size_t alias_count;
432-
size_t cur_alias_length;
433432
for (alias_count = 0;
434433
src->h_aliases[alias_count] != nullptr;
435434
alias_count++) {
436435
}
437436

438437
dest->h_aliases = node::Malloc<char*>(alias_count + 1);
439438
for (size_t i = 0; i < alias_count; i++) {
440-
cur_alias_length = strlen(src->h_aliases[i]);
441-
dest->h_aliases[i] = node::Malloc(cur_alias_length + 1);
442-
memcpy(dest->h_aliases[i], src->h_aliases[i], cur_alias_length + 1);
439+
const size_t cur_alias_size = strlen(src->h_aliases[i]) + 1;
440+
dest->h_aliases[i] = node::Malloc(cur_alias_size);
441+
memcpy(dest->h_aliases[i], src->h_aliases[i], cur_alias_size);
443442
}
444443
dest->h_aliases[alias_count] = nullptr;
445444

@@ -1065,7 +1064,6 @@ int ParseSoaReply(Environment* env,
10651064
/* Can't use ares_parse_soa_reply() here which can only parse single record */
10661065
unsigned int ancount = cares_get_16bit(buf + 6);
10671066
unsigned char* ptr = buf + NS_HFIXEDSZ;
1068-
int rr_type, rr_len;
10691067
char* name;
10701068
char* rr_name;
10711069
long temp_len; // NOLINT(runtime/int)
@@ -1094,8 +1092,8 @@ int ParseSoaReply(Environment* env,
10941092
break;
10951093
}
10961094

1097-
rr_type = cares_get_16bit(ptr);
1098-
rr_len = cares_get_16bit(ptr + 8);
1095+
const int rr_type = cares_get_16bit(ptr);
1096+
const int rr_len = cares_get_16bit(ptr + 8);
10991097
ptr += NS_RRFIXEDSZ;
11001098

11011099
/* only need SOA */

0 commit comments

Comments
 (0)