From 3f846f386c6e51f707ab418b549e4fb4180960de Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Mon, 13 Mar 2023 17:12:26 +0100 Subject: Change data return in clist_iterator_next We want only data and not the node structure. --- src/list.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/list.c') diff --git a/src/list.c b/src/list.c index 7714f5d..ea038f4 100644 --- a/src/list.c +++ b/src/list.c @@ -103,13 +103,17 @@ clist_iterator_has_next(iterator_t i) return i.current != NULL; } -list_item_t -clist_iterator_next(iterator_t *iterator) +void * +clist_iterator_next(iterator_t *i) { - struct list_item_t *current = iterator->current; - iterator->current = iterator->current->next; + if (i == NULL || i->current == NULL) + return NULL; - return current; + void *data = i->current->data; + /* `next` can be NULL */ + i->current = i->current->next; + + return data; } char * -- cgit v1.2.3