]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Check whether the field that's meant to be an fr_dlist_t is actually an fr_dlist_t
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jul 2018 02:05:14 +0000 (22:05 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jul 2018 02:05:14 +0000 (22:05 -0400)
Because when it's a fr_dlist_t *, and you don't notice, it's confusing when the 8 bytes preceeding the structure gets overwritten with a linked list pointer.

src/lib/util/dlist.h

index 3ba40809b59c5eea357d78f788fdf3523aaef442..e2883eb2a9391eb5b325bddf8894d089a2f8a8db 100644 (file)
@@ -80,7 +80,8 @@ static inline void fr_dlist_entry_init(fr_dlist_t *entry)
  *                     fr_dict_attr_t etc...
  * @param[in] _field   Containing the #fr_dlist_t within item being stored.
  */
-#define fr_dlist_init(_head, _type, _field) _fr_dlist_init(_head, offsetof(_type, _field), NULL)
+#define fr_dlist_init(_head, _type, _field) \
+       _Generic((((_type *)0)->_field), fr_dlist_t: _fr_dlist_init(_head, offsetof(_type, _field), NULL))
 
 /** Initialise the head structure of a doubly linked list
  *
@@ -94,7 +95,8 @@ static inline void fr_dlist_entry_init(fr_dlist_t *entry)
  *                     fr_dict_attr_t etc...
  * @param[in] _field   Containing the #fr_dlist_t within item being stored.
  */
-#define fr_dlist_talloc_init(_head, _type, _field) _fr_dlist_init(_head, offsetof(_type, _field), STRINGIFY(_type))
+#define fr_dlist_talloc_init(_head, _type, _field) \
+       _Generic((((_type *)0)->_field), fr_dlist_t: _fr_dlist_init(_head, offsetof(_type, _field), #_type))
 
 static inline void _fr_dlist_init(fr_dlist_head_t *head, size_t offset, char const *type)
 {