Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] Boost segfaults in archive/basic_xml_iarchive.hpp
From: Mccall, Kurt E. (JSC-EG411) (kurt.e.mccall_at_[hidden])
Date: 2015-06-19 15:53:50


If someone could help me diagnose this segmentation fault, I'd appreciate it greatly. It has stumped me for
a couple of days. I'm deserializing a non-polymorphic derived class, and Boost crashes when it attempts to
process the base class: Here is the pseudocode:

struct Base {
    int id_;
    std::string long_name_;

    template<Archive>
    void serialize(Archive & ar, const unsigned int file_version) {
        ar & BOOST_SERIALIZATION_NVP(id_);
ar & BOOST_SERIALIZATION_NVP(long_name_); // SEGFAULT OCCURS HERE
    }
}

struct Derived : public Base
{
    template<Archive>
    void serialize(Archive & ar, const unsigned int file_version) {
        ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
        …
    }
}

I tried the methods described at http://stackoverflow.com/questions/3396330/where-to-put-boost-class-export-for-boostserialization
for exporting the derived class using BOOST_CLASS_EXPORT, but none of them affected the segfault. I guess that it isn't really necessary
to export non-polymorphic derived classes.

Anyway, the code crashes in archive/basic_xml_iarchive.hpp in this code at line 92:

   // Anything not an attribute - see below - should be a name value
    // pair and be processed here
    typedef detail::common_iarchive<Archive> detail_common_iarchive;
    template<class T>
    void load_override(
       #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
        const
        #endif
        boost::serialization::nvp< T > & t,
        int
    ){
        this->This()->load_start(t.name());
        this->detail_common_iarchive::load_override(t.value(), 0); // SEGFAULT OCCURS HERE
        this->This()->load_end(t.name());
    }

In GDB, "this" has a valid address ( 0x7fffffffdb30) as does "t" (0x7ffffff487b0). In GDB, executing
t.name() yielded the correct name "long_name_", but when executing t.value(), the debugger
complained about an invalid address:

RuntimeError: Cannot access memory at address 0xffffffffffffffe8

That error message comes from GDB's Python utility for pretty-printing strings (the variable being deserialized is a std::string),
which is invoked when I print t.value(), but regardless something is wrong in t.value().

Does any of this suggest what I might be doing wrong? Thanks for any help.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net