Skip to content
Snippets Groups Projects
Commit 29ba1730 authored by Yang Tse's avatar Yang Tse
Browse files

attempt to fix compiler warning relative to potential misaligned data access

parent 18321061
No related branches found
No related tags found
No related merge requests found
...@@ -173,23 +173,36 @@ int Curl_num_addresses(const Curl_addrinfo *addr) ...@@ -173,23 +173,36 @@ int Curl_num_addresses(const Curl_addrinfo *addr)
/* /*
* Curl_printable_address() returns a printable version of the 1st address * Curl_printable_address() returns a printable version of the 1st address
* given in the 'ip' argument. The result will be stored in the buf that is * given in the 'ai' argument. The result will be stored in the buf that is
* bufsize bytes big. * bufsize bytes big.
* *
* If the conversion fails, it returns NULL. * If the conversion fails, it returns NULL.
*/ */
const char *Curl_printable_address(const Curl_addrinfo *ip, const char *
char *buf, size_t bufsize) Curl_printable_address(const Curl_addrinfo *ai, char *buf, size_t bufsize)
{ {
const void *ip4 = &((const struct sockaddr_in*)ip->ai_addr)->sin_addr; struct sockaddr_in *sa4;
int af = ip->ai_family; struct in_addr *ipaddr4;
#ifdef CURLRES_IPV6 #ifdef ENABLE_IPV6
const void *ip6 = &((const struct sockaddr_in6*)ip->ai_addr)->sin6_addr; struct sockaddr_in6 *sa6;
#else struct in6_addr *ipaddr6;
const void *ip6 = NULL;
#endif #endif
return Curl_inet_ntop(af, af == AF_INET ? ip4 : ip6, buf, bufsize); switch (ai->ai_family) {
case AF_INET:
sa4 = (struct sockaddr_in *)ai->ai_addr;
ipaddr4 = &sa4->sin_addr;
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize);
#ifdef ENABLE_IPV6
case AF_INET6:
sa6 = (struct sockaddr_in6 *)ai->ai_addr;
ipaddr6 = &sa6->sin6_addr;
return Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize);
#endif
default:
break;
}
return NULL;
} }
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment