[Bug 1011] New: KDL Tree.NrOfSegments() and SegmentMap.size() disagreement

http://bugs.orocos.org/show_bug.cgi?id=1011

Summary: KDL Tree.NrOfSegments() and SegmentMap.size()
disagreement
Product: KDL
Version: kdl-trunk
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P3
Component: Kinematic chains
AssignedTo: orocos-dev [..] ...
ReportedBy: earl [dot] darren [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

In KDL git repository with HEAD==8e450497c70c1a7cec2ff723fc7b482022c1640f
regarding
orocos_kinematics_dynamics/orocos_kdl/src/tree.hpp
orocos_kinematics_dynamics/orocos_kdl/src/tree.cpp

In Class KDL::Tree the NrOfSegments() function reports one less segment than is
in the SegmentMap segment member variable--presumably the root is not included
in the count of segments. The cause is in the constructor (Tree.cpp):

Tree::Tree(const std::string& _root_name) :
nrOfSegments(0), nrOfJoints(0),root_name(_root_name) {
segments.insert(make_pair(root_name, TreeElement::Root(root_name)));
}

Tree::Tree(const Tree& in) {
segments.clear();
nrOfSegments = 0;
nrOfJoints = 0;
root_name = in.root_name;

segments.insert(make_pair(root_name, TreeElement::Root(root_name)));
this->addTree(in, root_name);
}

nrOfSegments is initialized to zero but the root is inserted into segments.
The behaviour was responsible for an out-of-bounds array error in 3rd party
code.