summaryrefslogtreecommitdiffstats
path: root/src/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tree.c')
-rw-r--r--src/tree.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/tree.c b/src/tree.c
index ec5e72a..9d547b3 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -190,16 +190,24 @@ mq_tree_remove_allocated(MqTree *node)
{
MqTree *child;
- /* Link siblings and/or parent to children (may be NULL). */
+ /* Link siblings to children or each other. */
if (node->prev) {
- node->prev->next = node->first_child;
- } else {
- node->parent->first_child = node->first_child;
+ node->prev->next = node->first_child ?
+ node->first_child : node->next;
}
if (node->next) {
- node->next->prev = node->last_child;
- } else {
- node->parent->last_child = node->last_child;
+ node->next->prev = node->last_child ?
+ node->last_child : node->prev;
+ }
+
+ /* Update parent's links. */
+ if (node->parent->first_child == node) {
+ node->parent->first_child = node->first_child ?
+ node->first_child : node->next;
+ }
+ if (node->parent->last_child == node) {
+ node->parent->last_child = node->last_child ?
+ node->last_child : node->prev;
}
/* Link children to siblings (may be NULL). */