From 5f76a52e558a8069fe39ed668e96e9e14165dad3 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 24 Oct 2017 20:19:02 -0400 Subject: mq_tree_foreach_from(): Fix upward traversal Steps to reproduce bug: 1. From tab 1, append a new child 2. From tab 1, insert a new sibling 3. From tab 1, insert a new sibling The position of the last tab (the next sibling of the new tab inserted in step 3) gets updated twice. Tree debugging output: Traversing tree from position, starting at 0x12bf620 0x12bf620 0x1272f80 0x1272f80 Inserted sibling 0x12bf620, new tree (size 5): 0xe7f7f0 (size 5, position 0) 0xed3e10 (size 2, position 1) 0x114ef40 (size 1, position 2) 0x12bf620 (size 1, position 3) 0x1272f80 (size 1, position 5) --- (limited to 'src/tree.c') diff --git a/src/tree.c b/src/tree.c index ece8594..c3e2323 100644 --- a/src/tree.c +++ b/src/tree.c @@ -254,16 +254,17 @@ static gboolean foreach_up(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - if (node->next) { - if (foreach_down(node->next, cb, user_data) == MQ_TREE_STOP) { - return MQ_TREE_STOP; - } + node = node->parent; + if (!node) { + return MQ_TREE_CONTINUE; } - if (node->parent) { - if (foreach_up(node->parent, cb, user_data) == MQ_TREE_STOP) { - return MQ_TREE_STOP; - } + if (foreach_down(node->next, cb, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; + } + + if (foreach_up(node, cb, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; } return MQ_TREE_CONTINUE; -- cgit v0.9.1