My code below successfully converts a Binary search tree to a linked list however valgrind has been giving me "Conditional jump or move depends on uninitialised value(s)" errors. Yet after looking at my code, I don't see where I have that?
ListNodePtr convertBSTtoLinkedList(TreeNodePtr root)
{
ListNodePtr list,head;
list = malloc(sizeof(struct ListNode));
list->key = root->key;
if (root->right != NULL)
{
list->next = convertBSTtoLinkedList(root->right); //line 80
}
if (root->left != NULL)
{
ListNodePtr tail;
head = convertBSTtoLinkedList(root->left); //line 85
tail = head;
while (tail->next != NULL) { //Line 87
tail = tail->next;
}
tail->next = list;
return head;
}
return list;
}
This is my valgrind error, it repeats itself a few times.
==3076== Conditional jump or move depends on uninitialised value(s)
==3076== at 0x108AF2: convertBSTtoLinkedList (bst.c:87)
==3076== by 0x108AC8: convertBSTtoLinkedList (bst.c:80)
==3076== by 0x108ADD: convertBSTtoLinkedList (bst.c:85)
==3076== by 0x108ADD: convertBSTtoLinkedList (bst.c:85)
==3076== by 0x108ADD: convertBSTtoLinkedList (bst.c:85)
==3076== by 0x108AC8: convertBSTtoLinkedList (bst.c:80)
==3076== by 0x108AC8: convertBSTtoLinkedList (bst.c:80)
==3076== by 0x108754: main (main_bst.c:28)