diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tasktree.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/tasktree.cc b/src/tasktree.cc index c463177..39cee98 100644 --- a/src/tasktree.cc +++ b/src/tasktree.cc @@ -173,6 +173,17 @@ TaskIdList TaskTree::remove(taskid_t id) return affectedNodes; } +static bool findNode(node_t *needle, node_t *haystack) +{ + if(needle == haystack) return true; + NodeList::iterator i = haystack->children.begin(); + while(i != haystack->children.end()) { + if(findNode(needle, *i)) return true; + i++; + } + return false; +} + TaskIdList TaskTree::move(taskid_t id, taskid_t toid) throw (std::exception) { @@ -183,6 +194,9 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid) node_t* child = id2node.at(id); node_t* newparent = id2node.at(toid); + // Test if new parent is a child of the node itself... + if(findNode(newparent, child)) throw std::exception(); + if(!child->parent) { throw std::exception(); } |