Hi,
On 17/12/21 18:48, Zebediah Figura wrote:
--- a/include/private/rbtree.h +++ b/include/private/rbtree.h @@ -133,7 +133,7 @@ static inline struct rb_entry *rb_postorder_next(struct rb_entry *iter) /* iterate through the tree using a tree entry */ #define RB_FOR_EACH_ENTRY(elem, tree, type, field) \ for ((elem) = RB_ENTRY_VALUE(rb_head((tree)->root), type, field); \
&(elem)->field; \
(elem) != RB_ENTRY_VALUE(0, type, field); \ (elem) = RB_ENTRY_VALUE(rb_next(&elem->field), type, field))
Couldn't we take the chance to just avoid constructing dangling pointers (which is, as I read the C standard, undefined behavior)? That would amount, for example, to using
(elem) = (rb_next(&(elem)->field) ? RB_ENTRY_VALUE(rb_next(&(elem)->field), type, field) : NULL)
as iteration expression, similarly for the initialization expression and just checking that elem is not NULL for the condition expression.
Thanks, Giovanni.