Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-08-08 18:49:20


Ivan wrote:
> I'm running into what appears to be a bug in the serialization
> library, but maybe it is just a limitation on the library's usage.
> I'm not getting any exceptions thrown during
> serialization/deserialization, but I'm getting corrupted pointers
> after deserialiation.
>
> I'm trying to serialize/deserialize an object that contains a vector
> of objects containing vectors (something like below):
>
> class TObject
> {
> int x;
> }
>
> class TObjectContainer
> {
> std::vector<TObject> ObjectVector;
> };
>
> class TRoot
> {
> std::vector<TObjectContainer> ObjectContainerVector;
> std::vector <TObject*> ObjectPtrVector;
> };
>
> In simple cases, serializing/deserializing a structure like the above
> "appears" to work, but I believe the deserialization code has a bug
> or two.
>
> I think one bug is that the i index used to update the
> object_id_vectors in the reset_object_address is doubly incremented,
> which seems wrong at first glance (once in for-loop, then again at
> bottom of for-loop, basic_iarchive.cpp, lines 276 and 297).

This certainly looks like a bug to me - good call

> The other bug appears to be in the way moveable_objects_recent and
> moveable_objects_end are being set prior to calling
> reset_object_address. My assumption is the intent here is to modify
> the addresses of "trackable" sub-objects contained within the vector
> element being moved, so that ptrs will be hooked back up correctly,
> but the moveable ptrs are being set up in such a way that the vector
> elements (TObject) of the sub-vector (ObjectVector) are getting their
> addresses modified when the stack version of TObjectContainer is
> copied to the vector.

>This seems wrong, because the TObjects are
> allocated on the heap, so their addresses should not be updated in
> the object_vector_id table when the ObjectVector is copied. The end
> result is that I'm getting bad pointers to the TObjects after
> deserialization.

TObjects are de-serialized to the heap then added to the vector. Since
the tracking saves the address TObject is serialized to, the address
would be on the stack. reset_object_address sets the tracked
address to the heap address after the item is appended to the vector.

I thought I considered the case of a vector of vectors - but maybe
not. I would expect that the objects get theire addresses fixed up
twice- once when they are moved from the stack to the heap and
once when the vector container itself is moved from the stack to the heap.
Its
possible that there is something missng .

Robert Ramey

> best regards,
>
> Dan Notestein


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