Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong string deserialized in binary but not json? #724

Open
abrownsword opened this issue Nov 19, 2021 · 3 comments
Open

Wrong string deserialized in binary but not json? #724

abrownsword opened this issue Nov 19, 2021 · 3 comments

Comments

@abrownsword
Copy link

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 is wrong... it has the value of the corresponding string of the same member in the other std::vector!!

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
Copy link
Author

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.

@AzothAmmo
Copy link
Contributor

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

@abrownsword
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants