mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-21 23:50:37 +01:00
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.
This commit is contained in:
parent
445dcd9d9b
commit
dab2ee8ac5
11 changed files with 54 additions and 8 deletions
|
|
@ -241,6 +241,7 @@ _nmtstp_platform_ip_addresses_assert(const char *filename,
|
|||
if ((IS_IPv4 ? force_exact_4 : force_exact_6) && nm_g_ptr_array_len(plat_addrs) > 0) {
|
||||
char sbuf[sizeof(_nm_utils_to_string_buffer)];
|
||||
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("%s:%d: %u IPv%c addresses found on ifindex %d that should not be there (one "
|
||||
"is %s)",
|
||||
filename,
|
||||
|
|
@ -252,6 +253,7 @@ _nmtstp_platform_ip_addresses_assert(const char *filename,
|
|||
NMP_OBJECT_TO_STRING_PUBLIC,
|
||||
sbuf,
|
||||
sizeof(sbuf)));
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -580,6 +582,7 @@ _nmtstp_assert_ip4_route_exists(const char *file,
|
|||
if (c != c_exists && c_exists != -1) {
|
||||
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("[%s:%u] %s(): The ip4 route %s/%d metric %u tos %u shall exist %u times, but "
|
||||
"platform has it %u times",
|
||||
file,
|
||||
|
|
@ -591,6 +594,7 @@ _nmtstp_assert_ip4_route_exists(const char *file,
|
|||
tos,
|
||||
c_exists,
|
||||
c);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
|
||||
return r;
|
||||
|
|
@ -673,6 +677,7 @@ _nmtstp_assert_ip6_route_exists(const char *file,
|
|||
char s_src[NM_UTILS_INET_ADDRSTRLEN];
|
||||
char s_network[NM_UTILS_INET_ADDRSTRLEN];
|
||||
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("[%s:%u] %s(): The ip6 route %s/%d metric %u src %s/%d shall exist %u times, but "
|
||||
"platform has it %u times",
|
||||
file,
|
||||
|
|
@ -685,6 +690,7 @@ _nmtstp_assert_ip6_route_exists(const char *file,
|
|||
src_plen,
|
||||
c_exists,
|
||||
c);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
|
||||
return r;
|
||||
|
|
|
|||
|
|
@ -731,15 +731,17 @@ test_platform_ip_address_pretty_sort_cmp(gconstpointer test_data)
|
|||
&bin_len);
|
||||
|
||||
if (bin_len != ELM_SIZE * N_ADDRESSES || memcmp(addresses, bin_arr, bin_len) != 0) {
|
||||
char *addresses_str = nm_utils_bin2hexstr(addresses, ELM_SIZE * N_ADDRESSES, -1);
|
||||
gs_free char *addresses_str = NULL;
|
||||
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error(">>> test_platform_ip_address_pretty_sort_cmp() will fail:\n"
|
||||
">>> addresses[%zu]: %s\n"
|
||||
">>> expected [%zu]: %s\n",
|
||||
ELM_SIZE * N_ADDRESSES,
|
||||
addresses_str,
|
||||
(addresses_str = nm_utils_bin2hexstr(addresses, ELM_SIZE * N_ADDRESSES, -1)),
|
||||
bin_len,
|
||||
EXPECTED_BUFFER[TEST_DATA_I]);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
|
||||
g_assert_cmpmem(addresses, ELM_SIZE * N_ADDRESSES, bin_arr, bin_len);
|
||||
|
|
|
|||
|
|
@ -221,6 +221,7 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c
|
|||
success = g_file_set_contents(expected, content_written, len_written, &error);
|
||||
nmtst_assert_success(success, error);
|
||||
} else {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error(
|
||||
"The content of \"%s\" (%zu) differs from \"%s\" (%zu). Set "
|
||||
"NMTST_IFCFG_RH_UPDATE_EXPECTED=yes (or NM_TEST_REGENERATE=1) to update the files "
|
||||
|
|
@ -231,6 +232,7 @@ _assert_expected_content(NMConnection *connection, const char *filename, const c
|
|||
len_expectd,
|
||||
content_written,
|
||||
content_expectd);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2635,8 +2635,11 @@ _escape_filename(gboolean with_extension, const char *filename, gboolean would_b
|
|||
g_assert(esc && esc[0]);
|
||||
g_assert(!strchr(esc, '/'));
|
||||
|
||||
if (nm_keyfile_utils_ignore_filename(esc, with_extension))
|
||||
if (nm_keyfile_utils_ignore_filename(esc, with_extension)) {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("Escaping filename \"%s\" yielded \"%s\", but this is ignored", filename, esc);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -2327,13 +2327,14 @@ _do_read_vpn_details_impl1(const char *file,
|
|||
if (nm_streq(_expected[_i].key, _k)) \
|
||||
break; \
|
||||
} \
|
||||
if (_i >= _expected_len) \
|
||||
if (_i >= _expected_len) { \
|
||||
g_error("%s:%d: hash '%s' contains unexpected data key '%s' with value '%s'", \
|
||||
file, \
|
||||
line, \
|
||||
G_STRINGIFY(hash), \
|
||||
_k, \
|
||||
_v); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
for (_i = 0; _i < _expected_len; _i++) { \
|
||||
|
|
@ -2342,7 +2343,7 @@ _do_read_vpn_details_impl1(const char *file,
|
|||
g_assert(_d->key); \
|
||||
g_assert(_d->val); \
|
||||
_v = g_hash_table_lookup(_hash, _d->key); \
|
||||
if (!nm_streq0(_v, _d->val)) \
|
||||
if (!nm_streq0(_v, _d->val)) { \
|
||||
g_error("%s:%d: hash '%s' contains data key '%s' with value %s%s%s but we " \
|
||||
"expected '%s'", \
|
||||
file, \
|
||||
|
|
@ -2351,14 +2352,17 @@ _do_read_vpn_details_impl1(const char *file,
|
|||
_d->key, \
|
||||
NM_PRINT_FMT_QUOTE_STRING(_v), \
|
||||
_d->val); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
g_assert_cmpint(g_hash_table_size(_hash), ==, _expected_len); \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
_assert_hash(data, expected_data, expected_data_len);
|
||||
_assert_hash(secrets, expected_secrets, expected_secrets_len);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
|
||||
#undef _assert_hash
|
||||
return TRUE;
|
||||
|
|
@ -3049,10 +3053,12 @@ check_dbus_properties:
|
|||
break;
|
||||
p_expected_type++;
|
||||
if (p_expected_type >= &expected_types[G_N_ELEMENTS(expected_types)]) {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("D-Bus type \"%s\" is not implemented (in property %s.%s)",
|
||||
(const char *) mpr->dbus_type,
|
||||
mif->dbus_iface_name,
|
||||
mpr->dbus_property_name);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3151,6 +3157,7 @@ check_dbus_properties:
|
|||
break;
|
||||
}
|
||||
if (p_expected_type_2 >= &expected_types[G_N_ELEMENTS(expected_types)]) {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("D-Bus property \"%s.%s\" (type \"%s\") maps to property \"%s\", "
|
||||
"but that has an unexpected property type %s (expected %s)",
|
||||
mif->dbus_iface_name,
|
||||
|
|
@ -3159,6 +3166,7 @@ check_dbus_properties:
|
|||
pspec->name,
|
||||
g_type_name(pspec->value_type),
|
||||
g_type_name(p_expected_type->default_gtype));
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,9 @@ nmtstc_service_init(void)
|
|||
* via pygobject. */
|
||||
return NULL;
|
||||
}
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("test service %s exited with error code %d", NMTSTC_NM_SERVICE, data.exit_code);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4774,10 +4774,12 @@ check_done:;
|
|||
g_assert(NM_IS_SETTING_VPN(setting));
|
||||
g_assert_cmpstr(sip->name, ==, NM_SETTING_VPN_SECRETS);
|
||||
} else {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("secret %s.%s is of unexpected property type %s",
|
||||
nm_setting_get_name(setting),
|
||||
sip->name,
|
||||
g_type_name(sip->param_spec->value_type));
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4900,12 +4902,14 @@ check_done:;
|
|||
|
||||
/* the property-types with same content should all be shared. Here we have two that
|
||||
* are the same content, but different instances. Bug. */
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("The identical property type for D-Bus type \"%s\" is used by: %s and %s. "
|
||||
"If a NMSettInfoPropertType is identical, it should be shared by creating "
|
||||
"a common instance of the property type",
|
||||
(const char *) pt->dbus_type,
|
||||
_PROP_IDX_OWNER(h_property_types, pt),
|
||||
_PROP_IDX_OWNER(h_property_types, pt_2));
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1130,6 +1130,7 @@ nm_utils_parse_inaddr_bin_full(int addr_family,
|
|||
|
||||
#if NM_MORE_ASSERTS > 10
|
||||
if (addr_family == AF_INET) {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
gs_free_error GError *error = NULL;
|
||||
in_addr_t a;
|
||||
|
||||
|
|
@ -1145,6 +1146,7 @@ nm_utils_parse_inaddr_bin_full(int addr_family,
|
|||
error->message);
|
||||
}
|
||||
nm_assert(addrbin.addr4 == a);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -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, ...) \
|
||||
|
|
|
|||
|
|
@ -131,11 +131,13 @@ test_nmp_link_mode_all_advertised_modes_bits(void)
|
|||
|
||||
for (i = 0; i < (int) G_N_ELEMENTS(_nmp_link_mode_all_advertised_modes); i++) {
|
||||
if (flags[i] != _nmp_link_mode_all_advertised_modes[i]) {
|
||||
NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER
|
||||
g_error("_nmp_link_mode_all_advertised_modes[%d] should be 0x%0x but is 0x%0x "
|
||||
"(according to the bits in _nmp_link_mode_all_advertised_modes_bits)",
|
||||
i,
|
||||
flags[i],
|
||||
_nmp_link_mode_all_advertised_modes[i]);
|
||||
NM_PRAGMA_WARNING_REENABLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue