merge: branch 'th/gcc-14-fixes'

Fix compiler warnings with gcc-14 (mostly "-Wnonnull-compare")

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1840
This commit is contained in:
Beniamino Galvani 2024-02-07 08:42:58 +00:00
commit 2dbc4d16e6
6 changed files with 59 additions and 47 deletions

View file

@ -54,7 +54,8 @@ nm_dhcp_iaid_from_hexstr(const char *str, guint32 *out_value)
const char *
nm_net_devname_infiniband(char name[static NM_IFNAMSIZ], const char *parent_name, int p_key)
{
g_return_val_if_fail(name, NULL);
nm_assert(name);
g_return_val_if_fail(parent_name && parent_name[0], NULL);
g_return_val_if_fail(strlen(parent_name) < NM_IFNAMSIZ, NULL);

View file

@ -123,6 +123,7 @@ nm_team_link_watcher_new_ethtool(int delay_up, int delay_down, GError **error)
}
NM_PRAGMA_WARNING_DISABLE("-Warray-bounds")
NM_PRAGMA_WARNING_DISABLE("-Walloc-size")
watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
@ -131,6 +132,7 @@ nm_team_link_watcher_new_ethtool(int delay_up, int delay_down, GError **error)
watcher->ethtool.delay_up = delay_up;
watcher->ethtool.delay_down = delay_down;
NM_PRAGMA_WARNING_REENABLE
NM_PRAGMA_WARNING_REENABLE
return watcher;

View file

@ -311,10 +311,9 @@ _nm_wireguard_peer_set_public_key_bin(NMWireGuardPeer *self,
{
g_return_if_fail(NM_IS_WIREGUARD_PEER(self, FALSE));
nm_clear_g_free(&self->public_key);
nm_assert(public_key);
if (!public_key)
return;
nm_clear_g_free(&self->public_key);
self->public_key = g_base64_encode(public_key, NM_WIREGUARD_PUBLIC_KEY_LEN);
self->public_key_valid = TRUE;

View file

@ -5008,7 +5008,7 @@ nm_utils_bond_mode_string_to_int(const char *mode)
struct _NMUtilsStrStrDictKey {
char type;
char data[1];
char data[];
};
guint

View file

@ -195,48 +195,6 @@ _nm_auto_freev(gpointer ptr)
/*****************************************************************************/
#if defined(__GNUC__)
#define _NM_PRAGMA_WARNING_DO(warning) G_STRINGIFY(GCC diagnostic ignored warning)
#elif defined(__clang__)
#define _NM_PRAGMA_WARNING_DO(warning) G_STRINGIFY(clang diagnostic ignored warning)
#endif
/* you can only suppress a specific warning that the compiler
* understands. Otherwise you will get another compiler warning
* about invalid pragma option.
* It's not that bad however, because gcc and clang often have the
* same name for the same warning. */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("GCC diagnostic push")
#define NM_PRAGMA_WARNING_DISABLE(warning) \
NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO(warning))
#define NM_PRAGMA_WARNING_REENABLE _Pragma("GCC diagnostic pop")
#elif defined(__clang__)
#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("clang diagnostic push")
#define NM_PRAGMA_WARNING_DISABLE(warning) \
NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \
_Pragma(_NM_PRAGMA_WARNING_DO(warning))
#define NM_PRAGMA_WARNING_REENABLE _Pragma("clang diagnostic pop")
#else
#define NM_PRAGMA_DIAGNOSTICS_PUSH
#define NM_PRAGMA_WARNING_DISABLE(warning)
#define NM_PRAGMA_WARNING_REENABLE
#endif
/*****************************************************************************/
/* Seems gcc-12 has a tendency for false-positive -Wdangling-pointer warnings with
* g_error()'s `for(;;);`. See https://bugzilla.redhat.com/show_bug.cgi?id=2056613 .
* Work around, but only for the affected gcc 12.0.1. */
#if defined(__GNUC__) && __GNUC__ == 12 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ <= 1
#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_WARNING_DISABLE("-Wdangling-pointer")
#else
#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_DIAGNOSTICS_PUSH
#endif
/*****************************************************************************/
/**
* NM_G_ERROR_MSG:
* @error: (nullable): the #GError instance

View file

@ -83,6 +83,11 @@
/*****************************************************************************/
#define NM_STRINGIFY_ARG(contents) #contents
#define NM_STRINGIFY(macro_or_string) NM_STRINGIFY_ARG(macro_or_string)
/*****************************************************************************/
#ifndef _NM_CC_SUPPORT_AUTO_TYPE
#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)))
#define _NM_CC_SUPPORT_AUTO_TYPE 1
@ -209,6 +214,48 @@ typedef uint64_t _nm_bitwise nm_be64_t;
/*****************************************************************************/
#if defined(__GNUC__)
#define _NM_PRAGMA_WARNING_DO(warning) NM_STRINGIFY(GCC diagnostic ignored warning)
#elif defined(__clang__)
#define _NM_PRAGMA_WARNING_DO(warning) NM_STRINGIFY(clang diagnostic ignored warning)
#endif
/* you can only suppress a specific warning that the compiler
* understands. Otherwise you will get another compiler warning
* about invalid pragma option.
* It's not that bad however, because gcc and clang often have the
* same name for the same warning. */
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("GCC diagnostic push")
#define NM_PRAGMA_WARNING_DISABLE(warning) \
NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO(warning))
#define NM_PRAGMA_WARNING_REENABLE _Pragma("GCC diagnostic pop")
#elif defined(__clang__)
#define NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma("clang diagnostic push")
#define NM_PRAGMA_WARNING_DISABLE(warning) \
NM_PRAGMA_DIAGNOSTICS_PUSH _Pragma(_NM_PRAGMA_WARNING_DO("-Wunknown-warning-option")) \
_Pragma(_NM_PRAGMA_WARNING_DO(warning))
#define NM_PRAGMA_WARNING_REENABLE _Pragma("clang diagnostic pop")
#else
#define NM_PRAGMA_DIAGNOSTICS_PUSH
#define NM_PRAGMA_WARNING_DISABLE(warning)
#define NM_PRAGMA_WARNING_REENABLE
#endif
/*****************************************************************************/
/* Seems gcc-12 has a tendency for false-positive -Wdangling-pointer warnings with
* g_error()'s `for(;;);`. See https://bugzilla.redhat.com/show_bug.cgi?id=2056613 .
* Work around, but only for the affected gcc 12.0.1. */
#if defined(__GNUC__) && __GNUC__ == 12 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ <= 1
#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_WARNING_DISABLE("-Wdangling-pointer")
#else
#define NM_PRAGMA_WARNING_DISABLE_DANGLING_POINTER NM_PRAGMA_DIAGNOSTICS_PUSH
#endif
/*****************************************************************************/
/* glib/C provides the following kind of assertions:
* - assert() -- disable with NDEBUG
* - g_return_if_fail() -- disable with G_DISABLE_CHECKS
@ -241,6 +288,8 @@ typedef uint64_t _nm_bitwise nm_be64_t;
#define nm_assert(cond) \
({ \
NM_PRAGMA_WARNING_DISABLE("-Wnonnull-compare"); \
\
/* nm_assert() must do *nothing* of effect, except evaluating
* @cond (0 or 1 times).
*
@ -258,6 +307,9 @@ typedef uint64_t _nm_bitwise nm_be64_t;
} else { \
_nm_assert_fail(#cond); \
} \
\
NM_PRAGMA_WARNING_REENABLE; \
\
1; \
})