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.
This commit is contained in:
Diogo Cordeiro 2018-06-07 22:48:07 +01:00
parent b4faaca915
commit 5af4f108dc
1 changed files with 7 additions and 2 deletions

View File

@ -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);
}
}
}