From c0705faaf29e48bc92a39f02c50ec15862a1af3d Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 3 Apr 2024 15:23:57 +0200 Subject: [PATCH 1/5] Revert "fix gcc warnings" The patch doesn't fix compilation. This reverts commit 98cabe557f7d018efa5c49dd92504b3409359f6a. --- src/libnm-glib-aux/nm-uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index 69c34b2b98..df1b10c0ac 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -434,7 +434,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, { nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_232, TRUE); gsize slen; - const char *s = NULL; + const char *s; if (len >= 0) { gboolean has_nulls = FALSE; From 2386c0f52d07ebc3dac1441124d3cd6099d18384 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 3 Apr 2024 14:02:33 +0200 Subject: [PATCH 2/5] libnm-glib-aux: fix "maybe-uninitialized" error when generating UUID GCC 14 complans with: src/libnm-glib-aux/nm-uuid.c: In function 'nm_uuid_generate_from_strings_strv': src/libnm-glib-aux/nm-uuid.c:492:12: error: '_1' may be used uninitialized [-Werror=maybe-uninitialized] 492 | return nm_uuid_generate_from_string_str(s, slen, uuid_type, type_args); | ^ src/libnm-glib-aux/nm-uuid.c:392:1: note: by argument 1 of type 'const char *' to 'nm_uuid_generate_from_string_str' declared here 392 | nm_uuid_generate_from_string_str(const char *s, | ^ "-Wmaybe-uninitialized" diagnoses passing pointers or references to uninitialized memory to functions taking const-qualified arguments. In this case, nm_uuid_generate_from_string_str()'s first argument is a "const char *" and so the compiler expects that the string is always initialized. However, it is not initialized when len is zero. A non-null zero-length array can be specified in two ways: by setting len to zero, or by setting len to -1 and having NULL as first element. Handle both cases in the same way. --- src/libnm-glib-aux/nm-uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index df1b10c0ac..ff13c8fb11 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -436,7 +436,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, gsize slen; const char *s; - if (len >= 0) { + if (len > 0) { gboolean has_nulls = FALSE; gssize i; @@ -471,7 +471,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, * in the other cases). */ slen = 1; s = "x"; - } else if (!strv[0]) { + } else if (!strv[0] || len == 0) { slen = 0; s = ""; } else if (!strv[1]) { From fcea2f174e235f12eb4d3ec58d35662afc567173 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 3 Apr 2024 14:10:08 +0200 Subject: [PATCH 3/5] libnm-glib-aux: fix comments about UUID generation Whether the length is supplied explicitly or implicitly (via -1), the result is the same. Update the comment. --- src/libnm-glib-aux/nm-uuid.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c index ff13c8fb11..e39d2ea563 100644 --- a/src/libnm-glib-aux/nm-uuid.c +++ b/src/libnm-glib-aux/nm-uuid.c @@ -415,8 +415,7 @@ nm_uuid_generate_from_string_str(const char *s, * case the result is different from an empty array. * @len: if negative, @strv is a NULL terminated array. Otherwise, * it is the length of the strv array. In the latter case it may - * also contain NULL strings. The result hashes differently depending - * on whether we have a NULL terminated strv array or given length. + * also contain NULL strings. * * Returns a @uuid_type UUID based on the concatenated C strings. * It does not simply concatenate them, but also includes the @@ -478,7 +477,7 @@ nm_uuid_generate_from_strings_strv(NMUuidType uuid_type, slen = strlen(strv[0]) + 1u; s = strv[0]; } else { - /* We concatenate the NUL termiated string, including the NUL + /* We concatenate the NUL terminated string, including the NUL * character. This way, ("a","a"), ("aa"), ("aa","") all hash * differently. */ for (; strv[0]; strv++) From d369f5519244b4454b30376d36ed22b6777d7ee5 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 3 Apr 2024 16:51:54 +0200 Subject: [PATCH 4/5] 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. --- src/libnm-core-impl/nm-setting-team.c | 8 +------- 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; From 9ff7ff28fc15f0e34f6f30cbed63907f7b39b46f Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 4 Apr 2024 09:09:48 +0200 Subject: [PATCH 5/5] dcb: fix test compilation GCC 14 with LTO generates the following warning: src/core/tests/test-dcb.c: In function 'test_dcb_cleanup': src/core/tests/test-dcb.c:283:5: error: array subscript _3 is outside array bounds of 'const char *[0:]' [-Werror=array-bounds=] 283 | g_assert_cmpstr(expected.cmds[expected.num], ==, NULL); | ^ src/core/tests/test-dcb.c:14:17: note: while referencing 'cmds' 14 | const char *cmds[]; | ^ src/core/tests/test-dcb.c:261:24: note: defined here 'expected' 261 | static DcbExpected expected = { | ^ Define the commands as a fixed array instead of flexible array member. --- src/core/tests/test-dcb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tests/test-dcb.c b/src/core/tests/test-dcb.c index f85e90f990..33437974d5 100644 --- a/src/core/tests/test-dcb.c +++ b/src/core/tests/test-dcb.c @@ -11,7 +11,7 @@ typedef struct { guint num; - const char *cmds[]; + const char *cmds[16]; } DcbExpected; static gboolean