platform: ensure NM_SOCK_ADDR_UNION_INIT_UNSPEC() fully initializes union

In C, initialization of a union does not define that excess memory
is initialized. Ensure that, by initializing the largest member of the
NMSockAddrUnion union.
This commit is contained in:
Thomas Haller
2021-02-13 15:45:44 +01:00
parent b3909c36f6
commit 7bf2ddf73f

View File

@@ -34,10 +34,14 @@ typedef union {
struct sockaddr_in6 in6; struct sockaddr_in6 in6;
} NMSockAddrUnion; } NMSockAddrUnion;
G_STATIC_ASSERT(sizeof(NMSockAddrUnion) == sizeof(((NMSockAddrUnion *) NULL)->in6));
/* we initialize the largest union member, to ensure that all fields are initialized. */
#define NM_SOCK_ADDR_UNION_INIT_UNSPEC \ #define NM_SOCK_ADDR_UNION_INIT_UNSPEC \
{ \ { \
.sa = { \ .in6 = { \
.sa_family = AF_UNSPEC, \ .sin6_family = AF_UNSPEC, \
}, \ }, \
} }