diff options
author | Thomas Haller <thaller@redhat.com> | 2022-02-18 20:34:17 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-02-21 19:50:52 +0100 |
commit | dab2ee8ac5c025cc8f3dcb0f0aae7bcecab961e4 (patch) | |
tree | 15dc71e87d6a6c6edb8f1877a46f4b399322a974 /src/libnm-glib-aux/nm-test-utils.h | |
parent | 445dcd9d9b3bfe61da5860e6cc9f1e598a3ae376 (diff) | |
download | NetworkManager-dab2ee8ac5c025cc8f3dcb0f0aae7bcecab961e4.tar.gz |
all: suppress wrong gcc-12 warning "-Wdangling-pointer"
gcc-12.0.1-0.8.fc36 is annoying with false positives.
It's related to g_error() and its `for(;;) ;`.
For example:
../src/libnm-glib-aux/nm-shared-utils.c: In function 'nm_utils_parse_inaddr_bin_full':
../src/libnm-glib-aux/nm-shared-utils.c:1145:26: error: dangling pointer to 'error' may be used [-Werror=dangling-pointer=]
1145 | error->message);
| ^~
/usr/include/glib-2.0/glib/gmessages.h:343:32: note: in definition of macro 'g_error'
343 | __VA_ARGS__); \
| ^~~~~~~~~~~
../src/libnm-glib-aux/nm-shared-utils.c:1133:31: note: 'error' declared here
1133 | gs_free_error GError *error = NULL;
| ^~~~~
/usr/include/glib-2.0/glib/gmessages.h:341:25: error: dangling pointer to 'addrbin' may be used [-Werror=dangling-pointer=]
341 | g_log (G_LOG_DOMAIN, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
342 | G_LOG_LEVEL_ERROR, \
| ~~~~~~~~~~~~~~~~~~~~~~~
343 | __VA_ARGS__); \
| ~~~~~~~~~~~~
../src/libnm-glib-aux/nm-shared-utils.c:1141:13: note: in expansion of macro 'g_error'
1141 | g_error("unexpected assertion failure: could parse \"%s\" as %s, but not accepted by "
| ^~~~~~~
../src/libnm-glib-aux/nm-shared-utils.c:1112:14: note: 'addrbin' declared here
1112 | NMIPAddr addrbin;
| ^~~~~~~
I think the warning could potentially be useful and prevent real bugs.
So don't disable it altogether, but go through the effort to suppress it
at the places where it currently happens.
Note that NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER macro only expands
to suppressing the warning with __GNUC__ equal to 12. The purpose is to
only suppress the warning where we know we want to. Hopefully other gcc
versions don't have this problem.
I guess, we could also write a NM_COMPILER_WARNING() check in
"m4/compiler_options.m4", to disable the warning if we detect it. But
that seems too cumbersome.
Diffstat (limited to 'src/libnm-glib-aux/nm-test-utils.h')
-rw-r--r-- | src/libnm-glib-aux/nm-test-utils.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h index caf43d5f48..2dfe9e323e 100644 --- a/src/libnm-glib-aux/nm-test-utils.h +++ b/src/libnm-glib-aux/nm-test-utils.h @@ -1714,8 +1714,11 @@ __nmtst_spawn_sync(const char *working_directory, standard_err, &exit_status, &error); - if (!success) + if (!success) { + NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER g_error("nmtst_spawn_sync(%s): %s", ((char **) argv->pdata)[0], error->message); + NM_PRAGMA_WARNING_REENABLE + } g_assert(!error); g_assert(!standard_out || *standard_out); @@ -1844,7 +1847,8 @@ _nmtst_assert_resolve_relative_path_equals(const char *f1, /* Fixme: later we might need to coalesce repeated '/', "./", and "../". * For now, it's good enough. */ - if (g_strcmp0(p1, p2) != 0) + if (g_strcmp0(p1, p2) != 0) { + NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER g_error("%s:%d : filenames don't match \"%s\" vs. \"%s\" // \"%s\" - \"%s\"", file, line, @@ -1852,6 +1856,8 @@ _nmtst_assert_resolve_relative_path_equals(const char *f1, f2, p1, p2); + NM_PRAGMA_WARNING_REENABLE + } } #define nmtst_assert_resolve_relative_path_equals(f1, f2) \ _nmtst_assert_resolve_relative_path_equals(f1, f2, __FILE__, __LINE__); @@ -2404,9 +2410,11 @@ _nmtst_assert_connection_has_settings(NMConnection *connection, settings = nm_connection_get_settings(connection, &len); for (i = 0; i < len; i++) { if (!g_hash_table_remove(names, nm_setting_get_name(settings[i])) && has_at_most) { + NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER g_error( "nmtst_assert_connection_has_settings(): has setting \"%s\" which is not expected", nm_setting_get_name(settings[i])); + NM_PRAGMA_WARNING_REENABLE } } if (g_hash_table_size(names) > 0 && has_at_least) { @@ -2419,11 +2427,13 @@ _nmtst_assert_connection_has_settings(NMConnection *connection, settings_names[i] = nm_setting_get_name(settings[i]); has_str = g_strjoinv(" ", (char **) settings_names); + NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER g_error("nmtst_assert_connection_has_settings(): the setting lacks %u expected settings " "(expected: [%s] vs. has: [%s])", g_hash_table_size(names), expected_str, has_str); + NM_PRAGMA_WARNING_REENABLE } } #define nmtst_assert_connection_has_settings(connection, ...) \ |