diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-01-18 14:49:19 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-01-18 14:49:19 +0100 |
commit | ace5f9ead8c72f74616f96f7fd396b77391247d9 (patch) | |
tree | 779c02255b3dac4739a1fd12a9a7d28e6178657c /src | |
parent | b5b75f83a207c00d3582745bd2dc1866639028b6 (diff) |
Make sure we don't create cycle in the tree while moving...
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(); } |