Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54821 - trunk/libs/serialization/src
From: ramey_at_[hidden]
Date: 2009-07-08 18:55:36


Author: ramey
Date: 2009-07-08 18:55:36 EDT (Wed, 08 Jul 2009)
New Revision: 54821
URL: http://svn.boost.org/trac/boost/changeset/54821

Log:
Fix invalid pointer in unregister cast in void_cast.cpp
Text files modified:
   trunk/libs/serialization/src/extended_type_info.cpp | 7 +++++++
   trunk/libs/serialization/src/extended_type_info_typeid.cpp | 6 ++++++
   trunk/libs/serialization/src/void_cast.cpp | 30 +++++++++++++++---------------
   3 files changed, 28 insertions(+), 15 deletions(-)

Modified: trunk/libs/serialization/src/extended_type_info.cpp
==============================================================================
--- trunk/libs/serialization/src/extended_type_info.cpp (original)
+++ trunk/libs/serialization/src/extended_type_info.cpp 2009-07-08 18:55:36 EDT (Wed, 08 Jul 2009)
@@ -72,6 +72,13 @@
         assert(false);
         return false;
     };
+ virtual bool &
+ get_is_destroyed() const {
+ static bool dummy = true;
+ assert(false);
+ return dummy;
+ }
+
 public:
     extended_type_info_arg(const char * key) :
         extended_type_info()

Modified: trunk/libs/serialization/src/extended_type_info_typeid.cpp
==============================================================================
--- trunk/libs/serialization/src/extended_type_info_typeid.cpp (original)
+++ trunk/libs/serialization/src/extended_type_info_typeid.cpp 2009-07-08 18:55:36 EDT (Wed, 08 Jul 2009)
@@ -106,6 +106,12 @@
     public extended_type_info_typeid_0
 {
 private:
+ virtual bool &
+ get_is_destroyed() const {
+ static bool dummy = false;
+ assert(false);
+ return dummy;
+ }
 public:
     extended_type_info_typeid_arg(const std::type_info & ti){
         // note absense of self register and key as this is used only as

Modified: trunk/libs/serialization/src/void_cast.cpp
==============================================================================
--- trunk/libs/serialization/src/void_cast.cpp (original)
+++ trunk/libs/serialization/src/void_cast.cpp 2009-07-08 18:55:36 EDT (Wed, 08 Jul 2009)
@@ -222,27 +222,27 @@
 
     // delete all shortcuts which use this primitive
     void_cast_detail::set_type::iterator it;
- for(it = s.begin(); it != s.end(); ++it){
- if((*it)->is_shortcut()){
- if(m_derived == (*it)->m_base
- || (*it)->m_derived == m_base){
+ for(it = s.begin(); it != s.end();){
+ // note item 9 from Effective STL !!!
+ if((*it)->m_base == m_base && m_derived == (*it)->m_derived
+ && (
+ (*it)->m_base_is_destroyed
+ || (*it)->m_derived_is_destroyed
+ || *m_derived == *(*it)->m_base
+ || *(*it)->m_derived == *m_base
+ )){
+ // since recursion could invalidate it
+ const void_caster * vc = *it;
+ s.erase(it++);
+ if(vc->is_shortcut()){
                 // save pointer to set member
- const void_caster * vc = *it;
                 // and erase first
- s.erase(it);
- // since recursion could invalidate it
                 delete vc;
- it = s.begin();
             }
         }
+ else
+ it++;
     }
-
- const void_cast_detail::void_caster_argument ca(m_derived, m_base);
- it = s.find(& ca);
- if(s.end() == it)
- return;
-
- s.erase(it);
 }
 
 } // namespace void_cast_detail


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk