diff --git a/circ_list.c b/circ_list.c index a253d2cc25fa53f6b22d72d94c96cc89f51a9b16..f0900802f78ff67edfc4ad24aab2ba574e86172d 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 {