From 73010dc96357a9715b87421534bebc19ecd5863d Mon Sep 17 00:00:00 2001 From: Alexandre Jesus Date: Wed, 5 Oct 2016 18:42:30 +0100 Subject: Fix issues that would lead to seg fault on the online method --- src/dfs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/dfs.c') diff --git a/src/dfs.c b/src/dfs.c index b0bda53..12f4ee2 100644 --- a/src/dfs.c +++ b/src/dfs.c @@ -92,11 +92,12 @@ struct online_return dfs_online(struct data * data, struct front_item * front, s front_last->next = new_front_item(tree->values.p, tree->values.w, front_last, NULL); front_last = front_last->next; + /* Adjust prev and next */ + if(tree->prev != NULL) tree->prev->next = tree->next; + if(tree->next != NULL) tree->next->prev = tree->prev; + struct tree_item * old = tree; tree = tree->next; - if(tree != NULL) { - tree->prev = old->prev; - } free(old); change++; @@ -125,6 +126,10 @@ struct online_return dfs_online(struct data * data, struct front_item * front, s /* Update left next */ left->next = right; + /* Adjust prev and next */ + if(tree->prev != NULL) tree->prev->next = left; + if(tree->next != NULL) tree->next->prev = right; + /* Update tree to left node and free old node */ struct tree_item * old = tree; tree = left; -- cgit v1.2.3