[vlc-commits] Avoid arithmetic on NULL in VLC_OBJECT() kludge-macro
Rémi Denis-Courmont
git at videolan.org
Sat May 12 22:45:54 CEST 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May 12 23:40:32 2018 +0300| [b8c7cf13e274d58574c4574b44233a67a3e91450] | committer: Rémi Denis-Courmont
Avoid arithmetic on NULL in VLC_OBJECT() kludge-macro
If the offset of b within a is zero, then (&(a)->b) is equivalent to
casting a to a pointer to the type of the b member. However this implies
that a is a valid pointer. The expression is not valid if a is NULL.
Especially sanitizers do not like this.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b8c7cf13e274d58574c4574b44233a67a3e91450
---
include/vlc_objects.h | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index 8a107dbfad..f619936504 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -85,11 +85,10 @@ struct vlc_common_members
#if !defined(__cplusplus)
# define VLC_OBJECT(x) \
_Generic((x)->obj, \
- struct vlc_common_members: (vlc_object_t *)(&(x)->obj), \
- const struct vlc_common_members: (const vlc_object_t *)(&(x)->obj) \
+ struct vlc_common_members: (vlc_object_t *)(x) \
)
#else
-# define VLC_OBJECT( x ) ((vlc_object_t *)&(x)->obj)
+# define VLC_OBJECT(x) ((vlc_object_t *)(x))
#endif
/* Object flags */
More information about the vlc-commits
mailing list