Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Oct 29, 2024
1 parent ce2dddd commit b46ed22
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
9 changes: 1 addition & 8 deletions core-tests/src/network/dns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ TEST(dns, cancel) {
}

TEST(dns, getaddrinfo) {
char buf[1024] = {};
swoole::network::GetaddrinfoRequest req = {};
req.hostname = "www.baidu.com";
req.family = AF_INET;
req.socktype = SOCK_STREAM;
req.protocol = 0;
req.service = nullptr;
req.result = buf;
swoole::GetaddrinfoRequest req("www.baidu.com", AF_INET, SOCK_STREAM, 0, "");
ASSERT_EQ(swoole::network::getaddrinfo(&req), 0);
ASSERT_GT(req.count, 0);

Expand Down
2 changes: 1 addition & 1 deletion include/swoole_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class BitMap {
}

void clear() {
memset(array_, 0, get_array_size(n_bits_));
memset(array_, 0, sizeof(uint64_t) * get_array_size(n_bits_));
}

void set(size_t i) {
Expand Down
7 changes: 3 additions & 4 deletions src/network/dns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,21 +777,20 @@ int getaddrinfo(GetaddrinfoRequest *req) {
for (ptr = result; ptr != nullptr; ptr = ptr->ai_next, i++) {
}
req->count = SW_MIN(i, SW_DNS_HOST_BUFFER_SIZE);
req->results.resize(req->count);

for (ptr = result, i = 0; ptr != nullptr; ptr = ptr->ai_next, i++) {
char *buffer = (char *) &req->results[i];
switch (ptr->ai_family) {
case AF_INET:
memcpy(buffer, ptr->ai_addr, sizeof(struct sockaddr_in));
memcpy(&req->results[i], ptr->ai_addr, sizeof(struct sockaddr_in));
break;
case AF_INET6:
memcpy(buffer, ptr->ai_addr, sizeof(struct sockaddr_in6));
memcpy(&req->results[i], ptr->ai_addr, sizeof(struct sockaddr_in6));

Check warning on line 788 in src/network/dns.cc

View check run for this annotation

Codecov / codecov/patch

src/network/dns.cc#L788

Added line #L788 was not covered by tests
break;
default:
swoole_warning("unknown socket family[%d]", ptr->ai_family);
break;
}
i++;
if (i == SW_DNS_HOST_BUFFER_SIZE) {
break;
}
Expand Down

0 comments on commit b46ed22

Please sign in to comment.