summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-16 11:21:55 +0200
committerThomas Haller <thaller@redhat.com>2019-05-16 11:42:16 +0200
commitfbddd27e7383a60c2d72919b117d0ca3e7810a65 (patch)
tree3ee1b4075993d11d4c348324770e2dbacb628e48
parent98f41226737fb305d48ed431199307b1383f3a49 (diff)
downloadNetworkManager-fbddd27e7383a60c2d72919b117d0ca3e7810a65.tar.gz
shared: fix type shenanigans for data pointer of nm_memdup_maybe_a()
The type of the "data" pointer may not be compatible with the type of the "to_free" / output pointer. This is due to constness, and that we are unable in C to remove constness from a type. For example, { const char *const *data = ...; gs_free const char **cpy_to_free = NULL; const char **cpy; cpy = nm_memdup_maybe_a (300, data, NM_PTRARRAY_LEN (data) + 1, &cpy_to_free); } is prefectly valid , but would not have compiled. It shows that "data" is not of type "*(&cpy_to_free)", but rather it might be a non-const pointer of the same type. Fixes: d0e1d0e626d1 ('shared: propagate types in nm_malloc_maybe_a(), nm_malloc0_maybe_a(), nm_memdup_maybe_a()')
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index 1cae36c690..0d1f206d6c 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -1574,14 +1574,13 @@ nm_memdup (gconstpointer data, gsize size)
({ \
const gsize _size = (size); \
typeof (to_free) _to_free_md = (to_free); \
- typeof (*(_to_free_md)) _data = (data); \
- typeof (*(_to_free_md)) _ptr_md = NULL; \
+ 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; \