list: check for empty list before insert

We can't insert an empty list.
This commit is contained in:
Wim Taymans 2019-03-08 11:34:28 +01:00
parent 47fc2020c0
commit 964be84e1c
3 changed files with 7 additions and 7 deletions

@ -1 +1 @@
Subproject commit 42b4529c4caac63d521ea343d2029f59b47929b6
Subproject commit b50bd414ab497c461fcb2b25b545e59232dac7d1

View file

@ -95,8 +95,7 @@ spa_hook_list_isolate(struct spa_hook_list *list,
{
/* init save list and move hooks to it */
spa_hook_list_init(save);
if (!spa_list_is_empty(&list->list))
spa_list_insert_list(&save->list, &list->list);
spa_list_insert_list(&save->list, &list->list);
/* init hooks and add single hook */
spa_hook_list_init(list);
spa_hook_list_append(list, hook, funcs, data);
@ -106,8 +105,7 @@ static inline void
spa_hook_list_join(struct spa_hook_list *list,
struct spa_hook_list *save)
{
if (!spa_list_is_empty(&save->list))
spa_list_insert_list(&list->list, &save->list);
spa_list_insert_list(&list->list, &save->list);
}
#define spa_hook_call(hook,type,method,vers,...) \

View file

@ -41,6 +41,8 @@ static inline void spa_list_init(struct spa_list *list)
*list = SPA_LIST_INIT(list);
}
#define spa_list_is_empty(l) ((l)->next == (l))
static inline void spa_list_insert(struct spa_list *list, struct spa_list *elem)
{
elem->prev = list;
@ -51,6 +53,8 @@ static inline void spa_list_insert(struct spa_list *list, struct spa_list *elem)
static inline void spa_list_insert_list(struct spa_list *list, struct spa_list *other)
{
if (spa_list_is_empty(other))
return;
other->next->prev = list;
other->prev->next = list->next;
list->next->prev = other->prev;
@ -63,8 +67,6 @@ static inline void spa_list_remove(struct spa_list *elem)
elem->next->prev = elem->prev;
}
#define spa_list_is_empty(l) ((l)->next == (l))
#define spa_list_first(head, type, member) \
SPA_CONTAINER_OF((head)->next, type, member)