diff options
author | Thomas Haller <thaller@redhat.com> | 2022-08-25 19:43:40 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-08-25 21:15:38 +0200 |
commit | 04a97e4e854c7d77aced2716f58b7d4e0777f016 (patch) | |
tree | 6f1c34d7e0f8f5a8b96ea5224862f5bd0a6f94eb | |
parent | 97a2a566b4780b05e5a00db609643a24fc92fb99 (diff) | |
download | NetworkManager-04a97e4e854c7d77aced2716f58b7d4e0777f016.tar.gz |
std-aux: workaround maybe uninitialized warning with LTO on nm_ip_addr_is_null()
LTO without assertion enabled, thinks that certain code paths
result in uninitialized code. Technically, it's not wrong, in practice
those are only in cases where we already failed an assertion.
In function 'nm_ip_addr_is_null',
inlined from 'canonicalize_ip_binary' at src/libnm-core-impl/nm-setting-ip-config.c:67:21,
inlined from 'nm_ip_route_set_next_hop_binary' at src/libnm-core-impl/nm-setting-ip-config.c:1062:23:
./src/libnm-glib-aux/nm-inet-utils.h:80:12: error: 'a' may be used uninitialized [-Werror=maybe-uninitialized]
80 | return IN6_IS_ADDR_UNSPECIFIED(&a.addr6);
| ^
src/libnm-core-impl/nm-setting-ip-config.c: In function 'nm_ip_route_set_next_hop_binary':
./src/libnm-glib-aux/nm-inet-utils.h:73:14: note: 'a' declared here
73 | NMIPAddr a;
| ^
Try to workaround that by letting nm_utils_addr_family_to_size() always
return a non-zero size. This is ugly, because in the assertion case fail
we might now also get an additional memory corruption that could have
been avoided by returning zero. However, it probably doesn't matter, because
in this scenario we are already in a bad situation.
Fixes: b02aeaf2f3e0 ('glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses')
-rw-r--r-- | src/libnm-std-aux/nm-std-aux.h | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 77243ab186..95724252cb 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -1298,13 +1298,10 @@ nm_utils_addr_family_other(int addr_family) static inline size_t nm_utils_addr_family_to_size(int addr_family) { - switch (addr_family) { - case NM_AF_INET: - return NM_AF_INET_SIZE; - case NM_AF_INET6: + if (!NM_IS_IPv4(addr_family)) return NM_AF_INET6_SIZE; - } - return nm_assert_unreachable_val(0); + else + return NM_AF_INET_SIZE; } static inline size_t |