From 679927b5a9dc4dc3b3bb293dc94728db263b68f3 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 20 May 2008 11:14:16 +0200 Subject: [PATCH] Fix c_list_length() function. --- src/std/c_list.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/std/c_list.c b/src/std/c_list.c index e05fe728ea..bf944f82dd 100644 --- a/src/std/c_list.c +++ b/src/std/c_list.c @@ -199,6 +199,10 @@ c_list_t *c_list_alloc(void) { c_list_t *c_list_remove(c_list_t *list, void *data) { c_list_t *temp = NULL; + if (list == NULL || data == NULL) { + return NULL; + } + temp = list; while (temp != NULL) { @@ -275,13 +279,15 @@ c_list_t *c_list_previous(c_list_t *list) { * Gets the number of elements in a c_list */ unsigned long c_list_length(c_list_t *list) { - unsigned long length = 0; + unsigned long length = 1; - if (list != NULL) { - while (list->next) { - length++; - list = list->next; - } + if (list == NULL) { + return 0; + } + + while (list->next) { + length++; + list = list->next; } return length;