From 3a6eb5920e87e26b706d3770199faaa45542240f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 30 Jul 2021 10:48:59 +0200 Subject: [PATCH] all: use _NM_ENSURE_POINTER() macro --- src/libnm-glib-aux/nm-glib.h | 17 ++++++++------- src/libnm-glib-aux/nm-macros-internal.h | 11 ++++------ src/libnm-std-aux/nm-std-aux.h | 29 ++++++++++++------------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/libnm-glib-aux/nm-glib.h b/src/libnm-glib-aux/nm-glib.h index c283277b77..7f4ef04466 100644 --- a/src/libnm-glib-aux/nm-glib.h +++ b/src/libnm-glib-aux/nm-glib.h @@ -411,14 +411,15 @@ _nm_g_hash_table_get_keys_as_array(GHashTable *hash_table, guint *length) #undef g_steal_pointer #endif -#define g_steal_pointer(pp) \ - ({ \ - typeof(*(pp)) *const _pp = (pp); \ - typeof(*_pp) _p = *_pp; \ - _nm_unused const void *const _p_type_check = _p; \ - \ - *_pp = NULL; \ - _p; \ +#define g_steal_pointer(pp) \ + ({ \ + typeof(*(pp)) *const _pp = (pp); \ + typeof(*_pp) _p = *_pp; \ + \ + _NM_ENSURE_POINTER(_p); \ + \ + *_pp = NULL; \ + _p; \ }) /*****************************************************************************/ diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index a93dd610da..626311a75c 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -349,13 +349,10 @@ NM_G_ERROR_MSG(GError *error) * The only purpose of this macro is some additional compile time safety, * that the argument is a pointer to pointer. But then it will C cast any kind * of such argument. */ -#define NM_CAST_PPTR(type, arg) \ - ({ \ - typeof(*(arg)) *const _arg = (arg); \ - typeof(*_arg) _arg2 = _arg ? *_arg : NULL; \ - _nm_unused const void *const _arg3 = _arg2; \ - \ - (type **) _arg; \ +#define NM_CAST_PPTR(type, arg) \ + ({ \ + _NM_ENSURE_POINTER(*(arg)); \ + (type **) (arg); \ }) #if _NM_CC_SUPPORT_GENERIC diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index fc745bff86..8992c592df 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -410,12 +410,10 @@ _nm_ptrarray_len_impl(const void *const *array) * like g_strv_length() does. The difference is: * - it operates on arrays of pointers (of any kind, requiring no cast). * - it accepts NULL to return zero. */ -#define NM_PTRARRAY_LEN(array) \ - ({ \ - typeof(*(array)) *const _array = (array); \ - _nm_unused const void * _type_check_is_pointer = 0 ? _array[0] : NULL; \ - \ - _nm_ptrarray_len_impl((const void *const *) _array); \ +#define NM_PTRARRAY_LEN(array) \ + ({ \ + _NM_ENSURE_POINTER((array)[0]); \ + _nm_ptrarray_len_impl((const void *const *) (array)); \ }) /*****************************************************************************/ @@ -944,7 +942,7 @@ _nm_auto_fclose(FILE **pfd) int _changed = false; \ \ if (_pp && (_p = *_pp)) { \ - _nm_unused const void *_p_check_is_pointer = _p; \ + _NM_ENSURE_POINTER(_p); \ \ *_pp = NULL; \ \ @@ -967,14 +965,15 @@ _nm_auto_fclose(FILE **pfd) /*****************************************************************************/ -#define nm_steal_pointer(pp) \ - ({ \ - typeof(*(pp)) *const _pp = (pp); \ - typeof(*_pp) _p = *_pp; \ - _nm_unused const void *const _p_type_check = _p; \ - \ - *_pp = NULL; \ - _p; \ +#define nm_steal_pointer(pp) \ + ({ \ + typeof(*(pp)) *const _pp = (pp); \ + typeof(*_pp) _p = *_pp; \ + \ + _NM_ENSURE_POINTER(_p); \ + \ + *_pp = NULL; \ + _p; \ }) /**