cereal icon indicating copy to clipboard operation
cereal copied to clipboard

Wrong string deserialized in binary but not json?

Open abrownsword opened this issue 4 years ago • 3 comments

I am serializing a struct A which contains a few members include two length one std::vectors of struct B. B contains, among other things, a couple of strings. Struct A inherits from another class. Both structs (and the base class of the first) contain serialize methods that simply list all their members.

If I serialize to json, and then deserialize immediately, the result is correct. If I use a binary archive instead, however, then one of the strings in the first std::vector<B> is wrong... it has the value of the corresponding string of the same member in the other std::vector<B>!!

Any idea about what might be going on here or how to diagnose this? If not then I'll start trying to build an isolated repro case to figure out what is happening.

abrownsword avatar Nov 19 '21 22:11 abrownsword

To clarify a little:

struct B {
    std::string bad;
    std::string good;
};

struct A {
    std::vector<B> first;
    std::vector<B> second;
};

After deserialization, a.first[0].bad has been made a copy of a.second[0].good. And because we're using GCC <5.0 the string class is using ref counted data, so I know that the good string was copied (either explicitly or incidentally) to the bad string because the pointers to the string characters are identical.

abrownsword avatar Nov 22 '21 21:11 abrownsword

Would need a minimal running example to help further with this.

AzothAmmo avatar Nov 28 '21 03:11 AzothAmmo

Have worked around the problem for now, and will likely update the GCC version being used. Will not follow up on this issue unless it recurs (having read about the previous issue with GCC 4.8.x strings, I strongly suspect it is related).

abrownsword avatar Dec 09 '21 18:12 abrownsword