Commit c51f152b authored by Philip Withnall's avatar Philip Withnall

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/T7718Signed-off-by: 's avatarPhilip Withnall <withnall@endlessm.com>
Reviewed-by: Olivier Crête's avatarOlivier Crête <olivier.crete@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D1686
parent 1778f790
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment