summaryrefslogtreecommitdiff
path: root/src/nm-dispatcher
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-02-18 20:34:17 +0100
committerThomas Haller <thaller@redhat.com>2022-02-21 19:50:52 +0100
commitdab2ee8ac5c025cc8f3dcb0f0aae7bcecab961e4 (patch)
tree15dc71e87d6a6c6edb8f1877a46f4b399322a974 /src/nm-dispatcher
parent445dcd9d9b3bfe61da5860e6cc9f1e598a3ae376 (diff)
downloadNetworkManager-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/nm-dispatcher')
-rw-r--r--src/nm-dispatcher/tests/test-dispatcher-envp.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/nm-dispatcher/tests/test-dispatcher-envp.c b/src/nm-dispatcher/tests/test-dispatcher-envp.c
index f53bb1c137..51d31544ec 100644
--- a/src/nm-dispatcher/tests/test-dispatcher-envp.c
+++ b/src/nm-dispatcher/tests/test-dispatcher-envp.c
@@ -530,8 +530,11 @@ test_generic(const char *file, const char *override_vpn_ip_iface)
g_assert((!denv && error_message) || (denv && !error_message));
- if (error_message)
+ if (error_message) {
+ NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
g_error("FAILED: %s", error_message);
+ NM_PRAGMA_WARNING_REENABLE
+ }
if (g_strv_length(denv) != g_hash_table_size(expected_env)) {
_print_env(NM_CAST_STRV_CC(denv), expected_env);
@@ -552,8 +555,10 @@ test_generic(const char *file, const char *override_vpn_ip_iface)
foo = g_hash_table_lookup(expected_env, i_value);
if (!foo) {
+ NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
_print_env(NM_CAST_STRV_CC(denv), expected_env);
g_error("Failed to find %s in environment", i_value);
+ NM_PRAGMA_WARNING_REENABLE
}
}