Boost logo

Boost Users :

Subject: [Boost-users] Serialization / "Pointer conflict"
From: Dan Eaton (daniel.eaton_at_[hidden])
Date: 2009-05-14 18:16:12


Hi all,

Sorry for my last question; it was posted hastily -- I subsequently found the Reference->Special Considerations->Optimizations section.

Anyway, I have a new problem/question:

It's somewhat similar to the "pointer_conflict" example:

template<class T>
void save(T t)
{
        // create stream & output archive "oar"
        ar << t;
        // send with mpi/asio
}

template<class T>
T load()
{
        // retrieve string with mpi/asio
        T tmp;
        // create stream & input archive "iar"
        iar >> tmp;
        return tmp;
}

My problem (a few hours of debugging) was that on one end, I was passing in a pointer to an object:

FooClass *foo;
save(foo)

and on the deserialization end, I was requesting an object:

FooClass foo = load<FooClass>();

My mistake only showed up through the "array_size_too_short", since as part of the deserialization of FooClass, a fixed-length array was being deserialized, and I guess wonky parsing resulted in "count" being larger than "current_count" in iserializer.hpp.

Is what I was doing dangerous, or should/can the boost::serialization library somehow catch that mistake (i.e. in the serialized string, cant it not detect that the object is a pointer to an object, even if it's unregistered)?

My fix is to disallow the serialization of pointers on the forward side:

            if( boost::is_pointer<T> )
                throw exception

Thanks in advance for any thoughts you might share on the matter,

Danny


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