diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2024-04-03 16:51:54 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2024-04-05 11:40:45 +0200 |
commit | d369f5519244b4454b30376d36ed22b6777d7ee5 (patch) | |
tree | 0bb4059a64d55b4f2162e3c77c972e0f995b6925 | |
parent | fcea2f174e235f12eb4d3ec58d35662afc567173 (diff) |
libnm-core: avoid compiler warnings in team settings
GCC 14 with LTO complains with:
In function 'nm_team_link_watcher_new_ethtool',
inlined from 'nm_team_link_watcher_new_ethtool' at src/libnm-core-impl/nm-setting-team.c:106:1:
src/libnm-core-impl/nm-setting-team.c:130:33: error: array subscript 'struct NMTeamLinkWatcher[0]' is partly outside array bounds of 'unsigned char[16]' [-Werror=array-bounds=]
130 | watcher->ref_count = 1;
| ^
src/libnm-core-impl/nm-setting-team.c:128:15: note: object of size 16 allocated by 'g_malloc'
128 | watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
| ^
even if the warning is disabled via pragma directives in that
code. This looks like the following GCC bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80922
saying
We do not track warning options (and thus optimize pragmas /
attributes) across LTO because they are not saved in the function
specific optimization flag section.
We use a (NMTeamLinkWatcher *) to point to a memory area that is
shorter than the struct, because depending on the watcher type we need
to store different parameters; in this way we can save few bytes of
memory for some watcher types. However, this often breaks when
upgrading the compiler; instead just allocate the full struct.
-rw-r--r-- | src/libnm-core-impl/nm-setting-team.c | 8 | ||||
-rw-r--r-- | src/libnm-core-impl/nm-team-utils.c | 10 |
2 files changed, 2 insertions, 16 deletions
diff --git a/src/libnm-core-impl/nm-setting-team.c b/src/libnm-core-impl/nm-setting-team.c index 191ed9aef6..08364af88f 100644 --- a/src/libnm-core-impl/nm-setting-team.c +++ b/src/libnm-core-impl/nm-setting-team.c @@ -122,19 +122,13 @@ nm_team_link_watcher_new_ethtool(int delay_up, int delay_down, GError **error) return NULL; } - NM_PRAGMA_WARNING_DISABLE("-Warray-bounds") - NM_PRAGMA_WARNING_DISABLE("-Walloc-size") - - watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool)); + watcher = g_malloc(sizeof(NMTeamLinkWatcher)); watcher->ref_count = 1; watcher->type = LINK_WATCHER_ETHTOOL; watcher->ethtool.delay_up = delay_up; watcher->ethtool.delay_down = delay_down; - NM_PRAGMA_WARNING_REENABLE - NM_PRAGMA_WARNING_REENABLE - return watcher; } diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index 6f2f5dd298..21562163d2 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -2809,16 +2809,8 @@ NMTeamSetting * nm_team_setting_new(gboolean is_port, const char *js_str) { NMTeamSetting *self; - gsize l; - G_STATIC_ASSERT_EXPR(sizeof(*self) == sizeof(self->_data_priv)); - G_STATIC_ASSERT_EXPR( - sizeof(*self) - == NM_MAX(nm_offsetofend(NMTeamSetting, d.master), nm_offsetofend(NMTeamSetting, d.port))); - - l = is_port ? nm_offsetofend(NMTeamSetting, d.port) : nm_offsetofend(NMTeamSetting, d.master); - - self = g_malloc0(l); + self = g_malloc0(sizeof(NMTeamSetting)); self->_data_priv.is_port = is_port; self->_data_priv.strict_validated = TRUE; |