From c96200353dcec7bca428377d84579b282c0b78bd Mon Sep 17 00:00:00 2001 From: Brad House Date: Sun, 23 Jun 2024 20:11:27 -0400 Subject: [PATCH] valgrind: fix warning in test case --- test/ares-test.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/ares-test.cc b/test/ares-test.cc index 5adc9ceb..639609be 100644 --- a/test/ares-test.cc +++ b/test/ares-test.cc @@ -526,8 +526,12 @@ static unsigned short getaddrport(struct sockaddr_storage *addr) { if (addr->ss_family == AF_INET) return ntohs(((struct sockaddr_in *)(void *)addr)->sin_port); + if (addr->ss_family == AF_INET6) + return ntohs(((struct sockaddr_in6 *)(void *)addr)->sin6_port); - return ntohs(((struct sockaddr_in6 *)(void *)addr)->sin6_port); + /* TCP should use getpeername() to get the port, getting this from recvfrom + * won't work */ + return 0; } void MockServer::ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen, @@ -616,6 +620,7 @@ void MockServer::ProcessFD(ares_socket_t fd) { // Activity on a data-bearing file descriptor. struct sockaddr_storage addr; socklen_t addrlen = sizeof(addr); + memset(&addr, 0, sizeof(addr)); byte buffer[2048]; ares_ssize_t len = (ares_ssize_t)recvfrom(fd, BYTE_CAST buffer, sizeof(buffer), 0, (struct sockaddr *)&addr, &addrlen);