From ff5ec6af0290e5e8e6172e5d90d48f48edb7fe67 Mon Sep 17 00:00:00 2001 From: orange Date: Wed, 3 Jul 2013 09:31:50 +0200 Subject: [PATCH] properly initialize new list items --- linked-list.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linked-list.c b/linked-list.c index a6e18e2..68f968a 100644 --- a/linked-list.c +++ b/linked-list.c @@ -50,6 +50,8 @@ void list_print(list_t * list) { void list_add(list_t * list, list_node_t * item) { list_node_t *cur; + assert(item->next == NULL); + if (list_empty(list)) { list->head = item; } else { @@ -143,6 +145,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < howmany; i++) { list_node_t *newnode = malloc(sizeof(list_node_t)); newnode->data = i; + newnode->next = NULL; list_add(foolist, newnode); } @@ -200,6 +203,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < howmany2; i++) { list_node_t *newnode = malloc(sizeof(list_node_t)); newnode->data = i; + newnode->next = NULL; list_add(foolist, newnode); }