diff options
author | Thomas Haller <thaller@redhat.com> | 2022-11-30 09:49:32 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-12-06 17:03:04 +0100 |
commit | 06931221b56e3100f8819c696428d507d0140f30 (patch) | |
tree | 6b686b29b141009a0b57e08080e7ed1cd29488f0 | |
parent | 5ac5d7f8c3a5b42191f9b335e5994336c87c1178 (diff) |
std-aux: mark _nm_assert_fail() as _nm_unreachable_code() with NDEBUG/G_DISABLE_ASSERT
This is useful, because it can avoid compiler warnings that are
emitted if the compiler things that the code can be reached.
_nm_assert_fail() can clearly never be reached (unless a bug happens).
When compiling we can disable assertion checks with
NDEBUG/G_DISABLE_ASSERT, but if we know that an assertion must not be
hit (for example with nm_assert_not_reached()) then we still want to
mark the path as unreachable, even if assert() does not abort the
process.
-rw-r--r-- | src/libnm-glib-aux/nm-macros-internal.h | 9 | ||||
-rw-r--r-- | src/libnm-std-aux/nm-std-aux.h | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 085a27ff54..b8c754a41a 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -529,8 +529,13 @@ nm_str_realloc(char *str) /* redefine assertions to use g_assert*() */ #undef _nm_assert_fail -#define _nm_assert_fail(msg) \ - g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg) +#define _nm_assert_fail(msg) \ + G_STMT_START \ + { \ + g_assertion_message_expr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); \ + _nm_unreachable_code(); \ + } \ + G_STMT_END #undef _NM_ASSERT_FAIL_ENABLED #ifndef G_DISABLE_ASSERT diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index 1d1079456d..148cbe6199 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -246,6 +246,8 @@ _nm_assert_fail_internal(const char *assertion, #define _nm_assert_fail(msg) \ do { \ _nm_unused const char *_msg = (msg); \ + \ + _nm_unreachable_code(); \ } while (0) #endif |