Skip to content

Commit

Permalink
libmetal: add metal_list_for_each_safe() support
Browse files Browse the repository at this point in the history
Add a more secure way to traverse linked lists

Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
  • Loading branch information
GUIDINGLI authored and yintao committed Sep 12, 2023
1 parent 0bb6d9e commit d778210
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ static inline struct metal_list *metal_list_first(struct metal_list *list)
(node) != (list); \
(node) = (node)->next)

#define metal_list_for_each_safe(list, node, temp) \
for (node = (list)->next, temp = node->next; \
node != (list); node = temp, temp = node->next)

static inline bool metal_list_find_node(struct metal_list *list,
struct metal_list *node)
{
Expand Down

0 comments on commit d778210

Please sign in to comment.