glib-aux: ensure alignment for nm_ether_addr_zero

In practice, this does not cause an issue, because NMEtherAddr quite
quite obviously only contains uint8 values and has alignment 1.

It's still ugly to case nm_ip_addr_zero to NMEtherAddr if they are
entirely unrelated types.

Fixes: 58e2ba0535 ('glib-aux: drop ethernet fields from NMIPAddr union')
This commit is contained in:
Thomas Haller 2023-03-08 17:05:08 +01:00
parent f2f23a0f26
commit d960ef823d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 6 additions and 1 deletions

View file

@ -8,6 +8,11 @@ typedef union _NMIPAddr {
in_addr_t addr4;
struct in_addr addr4_struct;
struct in6_addr addr6;
/* This union field only exists, so that it's guaranteed that NMIPAddr has
* a suitable alignment. We use that with nm_ether_addr_zero macro, that
* aliases nm_ip_addr_zero. */
NMEtherAddr _ether_addr;
} NMIPAddr;
#define NM_IP_ADDR_INIT \

View file

@ -206,7 +206,7 @@ extern const union _NMIPAddr nm_ip_addr_zero;
/* Let's reuse nm_ip_addr_zero also for nm_ether_addr_zero. It's a union that
* also contains a NMEtherAddr field. */
#define nm_ether_addr_zero (*((const NMEtherAddr *) ((gconstpointer) &nm_ip_addr_zero)))
#define nm_ether_addr_zero (*((const NMEtherAddr *) &nm_ip_addr_zero))
static inline int
nm_ether_addr_cmp(const NMEtherAddr *a, const NMEtherAddr *b)