diff options
author | Alexandre Jesus <adbjesus@gmail.com> | 2016-10-05 18:42:30 +0100 |
---|---|---|
committer | Alexandre Jesus <adbjesus@gmail.com> | 2016-10-05 18:42:30 +0100 |
commit | 73010dc96357a9715b87421534bebc19ecd5863d (patch) | |
tree | 3dc42a2467ba8d2ff78ac54f2c3e2377de438b5c /src/dfs.c | |
parent | ddb004a2cc4ee7906f2167493da8d43b652ecdc4 (diff) | |
download | libuknapsack-73010dc96357a9715b87421534bebc19ecd5863d.tar.gz libuknapsack-73010dc96357a9715b87421534bebc19ecd5863d.zip |
Fix issues that would lead to seg fault on the online method
Diffstat (limited to 'src/dfs.c')
-rw-r--r-- | src/dfs.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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; |