id summary reporter owner description type status milestone component version severity resolution keywords cc 1849 Deserialization of std::string overwrites non-copied contents. Siegfried Kettlitz Robert Ramey "When a string is initialized with another string it doesn't copy the other strings contents but refers to it: {{{ const std::string Original( ""Hello"" ); std::string Foostring = Original; // Lazy copy. }}} When that copied string is deserialized, it overwrites the original string's contents. Instead it should always allocate new memory for a string when deserializing. One workaround is to initialize the string with the c_str() of the original string to enforce a copy: {{{ std::string Foostring = Original.c_str(); // Really copy the string. }}} The example was tested on Ubuntu 8.04 with gcc 4.2.3. ---- Code: {{{ #include #include #include #include #include #include #include #include void Test1() { const std::string Original( ""Hello"" ); std::string Foostring = Original; // Lazy copy. std::string Barstring( ""BarST"" ); std::cout << ""Original:"" << Original << "" Foostring:"" << Foostring << "" Barstring:"" << Barstring << std::endl; std::ostringstream OS(std::ios::binary); boost::archive::binary_oarchive OA( OS ); OA << Barstring; std::istringstream IS( OS.str(), std::ios::binary); boost::archive::binary_iarchive IA( IS ); IA >> Foostring; std::cout << ""Original:"" << Original << "" Foostring:"" << Foostring << "" Barstring:"" << Barstring << std::endl; } void Test2() { const std::string Original( ""Hello"" ); std::string Foostring = Original.c_str(); // Really copy the string. std::string Barstring( ""BarST"" ); std::cout << ""Original:"" << Original << "" Foostring:"" << Foostring << "" Barstring:"" << Barstring << std::endl; std::ostringstream OS(std::ios::binary); boost::archive::binary_oarchive OA( OS ); OA << Barstring; std::istringstream IS( OS.str(), std::ios::binary); boost::archive::binary_iarchive IA( IS ); IA >> Foostring; std::cout << ""Original:"" << Original << "" Foostring:"" << Foostring << "" Barstring:"" << Barstring << std::endl; } int main() { std::cout << ""Test1()"" << std::endl; Test1(); std::cout << ""Test2()"" << std::endl; Test2(); } }}} ---- Output: {{{ Test1() Original:Hello Foostring:Hello Barstring:BarST Original:BarST Foostring:BarST Barstring:BarST Test2() Original:Hello Foostring:Hello Barstring:BarST Original:Hello Foostring:BarST Barstring:BarST }}} " Bugs closed Boost 1.36.0 serialization Boost 1.35.0 Showstopper fixed