diff --git a/core-tests/src/network/dns.cpp b/core-tests/src/network/dns.cpp index cc7cd230024..cd4256c6d1b 100644 --- a/core-tests/src/network/dns.cpp +++ b/core-tests/src/network/dns.cpp @@ -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); diff --git a/include/swoole_util.h b/include/swoole_util.h index 8d6d10b11fb..2aa5a9d1721 100644 --- a/include/swoole_util.h +++ b/include/swoole_util.h @@ -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) { diff --git a/src/network/dns.cc b/src/network/dns.cc index e3a62f17fb8..22ac3ab9dd8 100644 --- a/src/network/dns.cc +++ b/src/network/dns.cc @@ -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)); break; default: swoole_warning("unknown socket family[%d]", ptr->ai_family); break; } - i++; if (i == SW_DNS_HOST_BUFFER_SIZE) { break; }