[Serialization] Bizarre bug

Hi, RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization bug to me, which I finally boiled down into the following piece of code: #include <sstream> #include <string> #include <vector> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/serialization/vector.hpp> template<typename Archive> struct X { template<typename T> void operator<<(const T &t) { Archive &archive = (*(Archive *) NULL); archive << t; } }; void dummy() { typedef boost::archive::text_oarchive Archive; X<Archive> &x = * (X<Archive> *) NULL; std::vector<char> *pt = NULL; // uncomment this line to cause the test to fail //x << pt; } int main(int argc, char* argv[]) { std::vector<char> v0(25, '%'); std::vector<char> v1; std::ostringstream ostr; boost::archive::text_oarchive(ostr) & v0; std::istringstream istr(ostr.str()); boost::archive::text_iarchive(istr) & v1; bool ok = (v0 == v1); return 0; } I find this odd, to say the least! I've tried it on Visual C++ 7.1, using boost 1.33.0 and 1.33.1. Regards, Jarl. http://www.codeproject.com/threads/Rcf_Ipc_For_Cpp.asp

Bizarre indeed - I'll look into it. Robert Ramey Jarl Lindrud wrote:
Hi,
RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization bug to me, which I finally boiled down into the following piece of code:
#include <sstream> #include <string> #include <vector>
#include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/serialization/vector.hpp>
template<typename Archive> struct X { template<typename T> void operator<<(const T &t) { Archive &archive = (*(Archive *) NULL); archive << t; } };
void dummy() { typedef boost::archive::text_oarchive Archive; X<Archive> &x = * (X<Archive> *) NULL; std::vector<char> *pt = NULL;
// uncomment this line to cause the test to fail //x << pt; }
int main(int argc, char* argv[]) { std::vector<char> v0(25, '%'); std::vector<char> v1;
std::ostringstream ostr; boost::archive::text_oarchive(ostr) & v0;
std::istringstream istr(ostr.str()); boost::archive::text_iarchive(istr) & v1;
bool ok = (v0 == v1); return 0; }
I find this odd, to say the least! I've tried it on Visual C++ 7.1, using boost 1.33.0 and 1.33.1.
Regards, Jarl.
http://www.codeproject.com/threads/Rcf_Ipc_For_Cpp.asp
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 8/19/06, Jarl Lindrud <jlindrud@hotmail.com> wrote:
Hi,
RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization bug to me, which I finally boiled down into the following piece of code:
Why there is so many dereferencing of null pointers in the example? Aren't such code illegal and relying in undefined behavior? -- Felipe Magno de Almeida

Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> writes:
On 8/19/06, Jarl Lindrud <jlindrud <at> hotmail.com> wrote:
Hi,
RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization
bug
to me, which I finally boiled down into the following piece of code:
Why there is so many dereferencing of null pointers in the example? Aren't such code illegal and relying in undefined behavior?
The compiler doesn't care about derefencing of null pointers, that's a runtime issue. The point is that the bug is being triggered by code that is never executed. Regards, Jarl.

After a cursory examination, I'm inclined to suspect this is a manifestation of a compiler bug. Could someone check this with another compiler? Robert Ramey Jarl Lindrud wrote:
Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> writes:
On 8/19/06, Jarl Lindrud <jlindrud <at> hotmail.com> wrote:
Hi,
RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization bug to me, which I finally boiled down into the following piece of code:
Why there is so many dereferencing of null pointers in the example? Aren't such code illegal and relying in undefined behavior?
The compiler doesn't care about derefencing of null pointers, that's a runtime issue. The point is that the bug is being triggered by code that is never executed.
Regards, Jarl.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

I Tried this with VC2005 Pro on Windows XP SP2, in both debug and release mode, it's OK, doesn't crash. Wang Yun Robert Ramey wrote:
After a cursory examination, I'm inclined to suspect this is a manifestation of a compiler bug. Could someone check this with another compiler?
Robert Ramey
Jarl Lindrud wrote:
Felipe Magno de Almeida <felipe.m.almeida <at> gmail.com> writes:
On 8/19/06, Jarl Lindrud <jlindrud <at> hotmail.com> wrote:
Hi,
RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization bug to me, which I finally boiled down into the following piece of code:
Why there is so many dereferencing of null pointers in the example? Aren't such code illegal and relying in undefined behavior?
The compiler doesn't care about derefencing of null pointers, that's a runtime issue. The point is that the bug is being triggered by code that is never executed.
Regards, Jarl.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Ah, yes, why I think it will crash... I test it again, the test failed in both debug and release mode. Wang Yun Jarl Lindrud wrote:
Wang Yun <a_hao <at> 21cn.com> writes:
I Tried this with VC2005 Pro on Windows XP SP2, in both debug and release mode, it's OK, doesn't crash.
Wang Yun
It's not supposed to crash :)
/Jarl.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

It does work on VC7.1 SP1. Is it suppose to crash? Christian

Robert Ramey <ramey <at> rrsd.com> writes:
After a cursory examination, I'm inclined to suspect this is a manifestation of a compiler bug. Could someone check this with another compiler?
Hi Robert, I've tried with 4 compilers, VC 7.1 & 8.0, GCC 3.2.3, and CodeWarrior 9.2, and the bug manifests itself on all of them, regardless of debug or release settings. /Jarl.

OK, thanks for helping with this. I'll look into it. Of course I would be interested in any other information on this that might come accross your path. Robert Ramey Jarl Lindrud wrote:
Robert Ramey <ramey <at> rrsd.com> writes:
After a cursory examination, I'm inclined to suspect this is a manifestation of a compiler bug. Could someone check this with another compiler?
Hi Robert,
I've tried with 4 compilers, VC 7.1 & 8.0, GCC 3.2.3, and CodeWarrior 9.2, and the bug manifests itself on all of them, regardless of debug or release settings.
/Jarl.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Jarl Lindrud wrote:
Hi,
RCF, a C++ middleware framework, supports using Boost Serialization for serialization of data structures. One of my user's reported a serialization bug to me, which I finally boiled down into the following piece of code:
I got curious and had a nose at this with vc8 and discovered a few things but not tracked the exact cause yet. It does fail for a start. The error seems to be in writing out the object id for the vector. If your commented out line is uncommented this causes instantiation of the pointer_oserializer for that type and when you subsequently serialize out the vector and it ends up in basic_oarchive_impl::save_object (basic_oarchive.cpp:241) the bpos parameter is non null and it takes one code path, but if your line is commented out then bpos is null (as pointer_oserializer::instantiate is never called) and it takes a different path. Down the path with your line commented in it then calls ar.vsave(oid) (basic_oarchive:285) to save out the object id and things get weird, it ends up writing an EOL to the stream which is what subsequently stuffs up the deserialization back again and causes the test to fail. Why all of this happens I dont know though and have run out of time for tonight ;) hth Martin
#include <sstream> #include <string> #include <vector>
#include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> #include <boost/serialization/vector.hpp>
template<typename Archive> struct X { template<typename T> void operator<<(const T &t) { Archive &archive = (*(Archive *) NULL); archive << t; } };
void dummy() { typedef boost::archive::text_oarchive Archive; X<Archive> &x = * (X<Archive> *) NULL; std::vector<char> *pt = NULL;
// uncomment this line to cause the test to fail //x << pt; }
int main(int argc, char* argv[]) { std::vector<char> v0(25, '%'); std::vector<char> v1;
std::ostringstream ostr; boost::archive::text_oarchive(ostr) & v0;
std::istringstream istr(ostr.str()); boost::archive::text_iarchive(istr) & v1;
bool ok = (v0 == v1); return 0; }
I find this odd, to say the least! I've tried it on Visual C++ 7.1, using boost 1.33.0 and 1.33.1.
Regards, Jarl.
http://www.codeproject.com/threads/Rcf_Ipc_For_Cpp.asp
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.405 / Virus Database: 268.11.3/423 - Release Date: 18/08/2006
participants (6)
-
Christian Henning
-
Felipe Magno de Almeida
-
Jarl Lindrud
-
Martin Slater
-
Robert Ramey
-
Wang Yun