[Boost-bugs] [Boost C++ Libraries] #6064: serialization fails with linked list of certain size

Subject: [Boost-bugs] [Boost C++ Libraries] #6064: serialization fails with linked list of certain size
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-10-27 08:33:02


#6064: serialization fails with linked list of certain size
------------------------------+---------------------------------------------
 Reporter: kajgol@… | Owner: ramey
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: serialization
  Version: Boost 1.47.0 | Severity: Showstopper
 Keywords: |
------------------------------+---------------------------------------------
 Serialization of a custom-made simple linked list fails if the list is of
 a certain size. Seems linked to the depth of pointers comming from the
 root. In the provided code if the NUM_OF_NODES is set to:
 * 1200 everything works
 * 1300 deserialization fails with a segfault
 * 1500 serialization fails with a segfault
 If the raw pointers are replaced with boost::shared_ptr the values of
 NUM_OF_NODES can be roughly cut in half to get the same effects.
 Changing the SerialTest classes size by adding additional fields has no
 effect.
 Compiled with gcc 4.5.2 from mingw on win xp

 {{{
 #include <iostream>
 #include <fstream>
 #include <vector>
 #include <boost/shared_ptr.hpp>
 #include <boost/serialization/shared_ptr.hpp>
 #include <boost/serialization/vector.hpp>
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/text_iarchive.hpp>

 using namespace std;

 class SerialTest
 {
 public:
         SerialTest* next;
         friend class boost::serialization::access;
         template<class Archive>
         void serialize(Archive & ar, const unsigned int version)
         {
                 ar & next;
         }
         SerialTest()
         {
         }
 };


 int main()
 {
         const size_t NUM_OF_NODES = 1200;
         SerialTest* root = new SerialTest;
         SerialTest* currentNode = root;
         for(size_t i = 0; i < NUM_OF_NODES; ++i)
         {
                 SerialTest* newNode = new SerialTest;
                 currentNode->next = newNode;
                 currentNode = newNode;
         }

         {
                 cout<<"opening ser file"<<endl;
                 ofstream of("test.t");
                 boost::archive::text_oarchive oa{of};
                 cout<<"serialization"<<endl;
                 oa << root;
         }

         {
                 cout<<"opening deser file"<<endl;
                 SerialTest* root2;
                 ifstream ifs("test.t");
                 cout<<"deserialization"<<endl;
                 boost::archive::text_iarchive ia{ifs};
                 ia >> root2;
         }
         cout<<"done"<<endl;

         return 0;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6064>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC