shared: propagate types in nm_malloc_maybe_a(), nm_malloc0_maybe_a(), nm_memdup_maybe_a()
The "to_free" pointer should have the suitable type that we are requesting. Use "typeof()" to preserve and propagate the pointer type in the macro.
This commit is contained in:
@@ -1534,8 +1534,8 @@ nm_memdup (gconstpointer data, gsize size)
|
||||
#define nm_malloc_maybe_a(alloca_maxlen, bytes, to_free) \
|
||||
({ \
|
||||
const gsize _bytes = (bytes); \
|
||||
gpointer _ptr; \
|
||||
typeof (to_free) _to_free = (to_free); \
|
||||
typeof (*_to_free) _ptr; \
|
||||
\
|
||||
G_STATIC_ASSERT_EXPR ((alloca_maxlen) <= 500); \
|
||||
nm_assert (_to_free && !*_to_free); \
|
||||
@@ -1553,8 +1553,8 @@ nm_memdup (gconstpointer data, gsize size)
|
||||
#define nm_malloc0_maybe_a(alloca_maxlen, bytes, to_free) \
|
||||
({ \
|
||||
const gsize _bytes = (bytes); \
|
||||
gpointer _ptr; \
|
||||
typeof (to_free) _to_free = (to_free); \
|
||||
typeof (*_to_free) _ptr; \
|
||||
\
|
||||
G_STATIC_ASSERT_EXPR ((alloca_maxlen) <= 500); \
|
||||
nm_assert (_to_free && !*_to_free); \
|
||||
@@ -1573,14 +1573,15 @@ nm_memdup (gconstpointer data, gsize size)
|
||||
#define nm_memdup_maybe_a(alloca_maxlen, data, size, to_free) \
|
||||
({ \
|
||||
const gsize _size = (size); \
|
||||
gpointer _ptr_md = NULL; \
|
||||
typeof (to_free) _to_free_md = (to_free); \
|
||||
typeof (*(_to_free_md)) _data = (data); \
|
||||
typeof (*(_to_free_md)) _ptr_md = NULL; \
|
||||
\
|
||||
nm_assert (_to_free_md && !*_to_free_md); \
|
||||
\
|
||||
if (_size > 0u) { \
|
||||
_ptr_md = nm_malloc_maybe_a ((alloca_maxlen), _size, _to_free_md); \
|
||||
memcpy (_ptr_md, (data), _size); \
|
||||
memcpy (_ptr_md, _data, _size); \
|
||||
} \
|
||||
\
|
||||
_ptr_md; \
|
||||
|
Reference in New Issue
Block a user