From 19a41e5a1095504a524333879593b8945fe8ea06 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 28 Nov 2013 21:26:55 +0100 Subject: Fix iTaSC build error when building with libc++. This was using TreeElement before it was fully defined, which gives undefined behavior that happened to work with other libraries but not libc++. Based on patch by Marcus von Appen, modifications for brevity and to ensure we don't dereference invalid memory. Ref T37477. --- intern/itasc/kdl/tree.hpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'intern/itasc/kdl/tree.hpp') diff --git a/intern/itasc/kdl/tree.hpp b/intern/itasc/kdl/tree.hpp index 82794f96b94..8f971200969 100644 --- a/intern/itasc/kdl/tree.hpp +++ b/intern/itasc/kdl/tree.hpp @@ -41,32 +41,28 @@ namespace KDL { //Forward declaration class TreeElement; -#if defined(__APPLE__) -# if MAC_OS_X_VERSION_MIN_REQUIRED <= 1050 +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED <= 1050 typedef std::map SegmentMap; -# else - // Eigen allocator is needed for alignment of Eigen data types - typedef std::map, Eigen::aligned_allocator > > SegmentMap; -# endif /* MAC_OS_X_VERSION_MIN_REQUIRED */ #else // Eigen allocator is needed for alignment of Eigen data types typedef std::map, Eigen::aligned_allocator > > SegmentMap; #endif + class TreeElement { public: - TreeElement():q_nr(0) + TreeElement():q_nr(0),parent(0) {}; public: Segment segment; unsigned int q_nr; - SegmentMap::const_iterator parent; + SegmentMap::value_type const *parent; std::vector children; - TreeElement(const Segment& segment_in,const SegmentMap::const_iterator& parent_in,unsigned int q_nr_in) + TreeElement(const Segment& segment_in,const SegmentMap::value_type& parent_in,unsigned int q_nr_in) { q_nr=q_nr_in; segment=segment_in; - parent=parent_in; + parent=&parent_in; }; static TreeElement Root() { @@ -167,7 +163,15 @@ namespace KDL return segments.find(segment_name); }; + SegmentMap::value_type const* getSegmentPtr(const std::string& segment_name)const + { + SegmentMap::const_iterator it = segments.find(segment_name); + + if (it == segments.end()) + return 0; + return &*it; + }; const SegmentMap& getSegments()const { -- cgit v1.2.3