Re: [Boost-bugs] [Boost C++ Libraries] #13006: serialization optional doesn't initialize stack_construct causes crashes

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #13006: serialization optional doesn't initialize stack_construct causes crashes
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-05-05 14:51:14


#13006: serialization optional doesn't initialize stack_construct causes crashes
-------------------------------------+---------------------------
  Reporter: rob.vandennieuwenhof@… | Owner: ramey
      Type: Bugs | Status: new
 Milestone: Boost 1.65.0 | Component: serialization
   Version: Boost 1.64.0 | Severity: Regression
Resolution: | Keywords:
-------------------------------------+---------------------------

Comment (by alexanderponkratov@…):

 read access violation while loading boost::optional<std::map<std::string,
 boost::shared_ptr<MyUDT> > >

 boost 1.64, compiler MSVC-2017.
 This code works fine with boost 1.63, but fails with 1.64.

 {{{
 #include <fstream>
 #include <map>
 #include <string>
 #include <boost/optional.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/archive/binary_oarchive.hpp>
 #include <boost/archive/binary_iarchive.hpp>
 #include <boost/serialization/map.hpp>
 #include <boost/serialization/optional.hpp>
 #include <boost/serialization/shared_ptr.hpp>
 #include <boost/serialization/string.hpp>

 struct MyUDT {
         boost::optional<std::map<std::string, boost::shared_ptr<MyUDT> > >
 val;

         template<class Archive>
         void serialize(Archive & ar, const unsigned int version)
         {
                 ar & val;
         }
 };

 int main()
 {
         std::ofstream ofs("filename");

         MyUDT obj;
         obj.val = std::map<std::string, boost::shared_ptr<MyUDT> >();
         obj.val.get()["test_key"] = boost::shared_ptr<MyUDT>(new MyUDT());

         // save data to archive
         {
                 boost::archive::binary_oarchive oa(ofs);
                 // write class instance to archive
                 oa << obj;
                 // archive and stream closed when destructors are called
         }

         // ... some time later restore the class instance to its orginal
 state
         MyUDT newObj;
         {
                 // create and open an archive for input
                 std::ifstream ifs("filename");
                 boost::archive::binary_iarchive ia(ifs);
                 // read class state from archive
                 ia >> newObj; // ERROR: read access violation
                 // archive and stream closed when destructors are called
         }

         return 0;
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/13006#comment:3>
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-05-05 14:54:48 UTC