From f8693ea6ce246a7dfb5a1100cbb2d816e8380381 Mon Sep 17 00:00:00 2001 From: Florian Burgener <florian.burgener@etu.hesge.ch> Date: Tue, 11 Jan 2022 13:24:55 +0100 Subject: [PATCH] Fix missing empty list checks --- circ_list.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/circ_list.c b/circ_list.c index a253d2c..f090080 100644 --- a/circ_list.c +++ b/circ_list.c @@ -27,6 +27,10 @@ unsigned int list_count(element *head) { } element *list_move(element *head) { + if (list_empty(head)) { + return NULL; + } + return head->next; } @@ -59,6 +63,10 @@ element *list_insert_before(element *head, int data) { } element *list_search(element *head, int data, int (*compare)(int, int)) { + if (list_empty(head)) { + return NULL; + } + element *iterator = head; do { @@ -91,6 +99,10 @@ element *list_remove(element *head, int data, int (*compare)(int, int)) { } void list_free(element *head) { + if (list_empty(head)) { + return; + } + element *iterator = head; do { @@ -101,6 +113,10 @@ void list_free(element *head) { } void list_process(element *head, int (*action)(int)) { + if (list_empty(head)) { + return; + } + element *iterator = head; do { -- GitLab