From 5af4f108dc492a1df99b9c6268c830d3fba62264 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Thu, 7 Jun 2018 22:48:07 +0100 Subject: [PATCH] cfulist_delete_data now works for the first item This function would crash for the first item. Now it calls cfulist_dequeue to remove the first element when necessary. --- src/cfulist.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cfulist.c b/src/cfulist.c index a55c41f..9a5e536 100644 --- a/src/cfulist.c +++ b/src/cfulist.c @@ -425,9 +425,14 @@ cfulist_delete_data(cfulist_t *list, void *data) { if (list->entries) { for (ptr = list->entries; ptr && ptr->data != data; ptr = ptr->next) ; + if (ptr && ptr->data == data) { - (ptr->prev)->next = ptr->next; - free (ptr); + if (!ptr->prev) { + cfulist_dequeue (list); + } else { + (ptr->prev)->next = ptr->next; + free (ptr); + } } }