diff options
author | Thomas Haller <thaller@redhat.com> | 2023-03-08 17:05:08 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-03-08 17:12:25 +0100 |
commit | d960ef823d49776bbb00f17e3f29b4ab790aaf61 (patch) | |
tree | 66c31b6e7dd1954cfb24a59cba3d4cb491bfd423 | |
parent | f2f23a0f2609cdbe5717f30e3273c58ef51ae0c3 (diff) | |
download | NetworkManager-d960ef823d49776bbb00f17e3f29b4ab790aaf61.tar.gz |
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: 58e2ba053535 ('glib-aux: drop ethernet fields from NMIPAddr union')
-rw-r--r-- | src/libnm-glib-aux/nm-inet-utils.h | 5 | ||||
-rw-r--r-- | src/libnm-glib-aux/nm-shared-utils.h | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/libnm-glib-aux/nm-inet-utils.h b/src/libnm-glib-aux/nm-inet-utils.h index af7620179c..40ba60c653 100644 --- a/src/libnm-glib-aux/nm-inet-utils.h +++ b/src/libnm-glib-aux/nm-inet-utils.h @@ -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 \ diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 618e34853b..accdd47063 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -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) |