summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-25 11:19:48 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-25 11:19:48 (EDT)
commit5fd86cc3febf71d17bfe9631ffbeccbd888495bf (patch)
tree71a77e8ba467adeba783d4fbe8f50d779681f2cc
parent310c6504735e940f08b2e8a0bfceb47f6646b820 (diff)
downloadmarquee-5fd86cc3febf71d17bfe9631ffbeccbd888495bf.zip
marquee-5fd86cc3febf71d17bfe9631ffbeccbd888495bf.tar.gz
marquee-5fd86cc3febf71d17bfe9631ffbeccbd888495bf.tar.bz2
mq_tree_remove*(): Fix parent and sibling links
-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). */