mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-08 10:14:04 +02:00
gmacros: Avoid casting functions
gmacros.h casts functions to GDestroyNotify, which prevents enabling the following hardening options in applications: -fsanitize=address -fsanitize=cfi-icall (without -fsanitize-cfi-icall-generalize-pointers), and -Wcast-function-type-strict. Define another inline function that warps the original function into GDestroyNotify. Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
This commit is contained in:
@@ -1337,6 +1337,7 @@
|
|||||||
/* these macros are private; note that gstdio.h also uses _GLIB_CLEANUP */
|
/* these macros are private; note that gstdio.h also uses _GLIB_CLEANUP */
|
||||||
#define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
|
#define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
|
||||||
#define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
|
#define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
|
||||||
|
#define _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName) glib_autoptr_destroy_##TypeName
|
||||||
#define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
|
#define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
|
||||||
#define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
|
#define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
|
||||||
#define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
|
#define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
|
||||||
@@ -1356,12 +1357,14 @@
|
|||||||
{ if (_ptr) (cleanup) ((ParentName *) _ptr); } \
|
{ if (_ptr) (cleanup) ((ParentName *) _ptr); } \
|
||||||
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) \
|
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) \
|
||||||
{ _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); } \
|
{ _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); } \
|
||||||
|
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName) (void *_ptr) \
|
||||||
|
{ (cleanup) ((ParentName *) _ptr); } \
|
||||||
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) \
|
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) \
|
||||||
{ g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \
|
{ g_list_free_full (*_l, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \
|
||||||
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) \
|
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) \
|
||||||
{ g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) cleanup); } \
|
{ g_slist_free_full (*_l, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \
|
||||||
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) (GQueue **_q) \
|
static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) (GQueue **_q) \
|
||||||
{ if (*_q) g_queue_free_full (*_q, (GDestroyNotify) (void(*)(void)) cleanup); } \
|
{ if (*_q) g_queue_free_full (*_q, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||||
#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
|
#define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
|
||||||
_GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
|
_GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
|
||||||
|
Reference in New Issue
Block a user