summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-03-03 10:19:20 +0000
committerPhilip Withnall <withnall@endlessm.com>2017-03-28 16:46:48 +0100
commitc51f152bc7699276c843d42833ecb5b334b06d7b (patch)
treef728de194ae9083893066ca9762a6178d9a43e93
parent1778f790087ab7663975ea466527c252eaccc5e3 (diff)
downloadlibnice-c51f152bc7699276c843d42833ecb5b334b06d7b.tar.gz
stun: Fix cast-align compiler warning when casting sockaddr
There should never be a problem with alignment at runtime, since we’re casting the sockaddr to sockaddr_in or sockaddr_in6 based on its declared sa_family — anything declared as AF_INET6 should have been allocated as a sockaddr_in6, and hence have appropriate alignment (same for AF_INET). This fixes a compiler warning on ARM and other alignment-sensitive architectures. https://phabricator.freedesktop.org/T7718 Signed-off-by: Philip Withnall <withnall@endlessm.com> Reviewed-by: Olivier Crête <olivier.crete@collabora.com> Differential Revision: https://phabricator.freedesktop.org/D1686
-rw-r--r--stun/stunmessage.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/stun/stunmessage.c b/stun/stunmessage.c
index 558fe5e..e8184c4 100644
--- a/stun/stunmessage.c
+++ b/stun/stunmessage.c
@@ -427,14 +427,22 @@ stun_message_append_addr (StunMessage *msg, StunAttribute type,
uint16_t alen, port;
uint8_t family;
+ union {
+ const struct sockaddr *addr;
+ const struct sockaddr_in *in;
+ const struct sockaddr_in6 *in6;
+ } sa;
+
if ((size_t) addrlen < sizeof (struct sockaddr))
return STUN_MESSAGE_RETURN_INVALID;
+ sa.addr = addr;
+
switch (addr->sa_family)
{
case AF_INET:
{
- const struct sockaddr_in *ip4 = (const struct sockaddr_in *)addr;
+ const struct sockaddr_in *ip4 = sa.in;
family = 1;
port = ip4->sin_port;
alen = 4;
@@ -444,7 +452,7 @@ stun_message_append_addr (StunMessage *msg, StunAttribute type,
case AF_INET6:
{
- const struct sockaddr_in6 *ip6 = (const struct sockaddr_in6 *)addr;
+ const struct sockaddr_in6 *ip6 = sa.in6;
if ((size_t) addrlen < sizeof (*ip6))
return STUN_MESSAGE_RETURN_INVALID;