[serialization] Exception basic_string::resize - possible bug in string archiving?

I hate to post this as it's late and I can't help thinking I'm missing something obvious, but here goes. I am getting an exception thrown as a result of executing line 52 of boost/trunk/boost/archive/impl/basic_binary_iarchive.ipp (yes I'm using trunk, but this happens with my 1.34.1 also) The little program shown below causes it, the output of which is, "std::exception: basic_string::resize" I'm using gcc 4.2 on Debian fwiw. --- #include <boost/archive/binary_iarchive.hpp> #include <iostream> #include <string> #include <sstream> int main() { std::string SimpleString( "Archive" ); std::istringstream InputStringStream( SimpleString ); try { boost::archive::binary_iarchive iarchive( InputStringStream ); } catch( const std::exception& e ) { std::cout << "std::exception: " << e.what() << std::endl; } return 0; } --- So am I missing the obvious or is there something more going on here? Thanks, Jamie

Jamie Allsop wrote:
I hate to post this as it's late and I can't help thinking I'm missing something obvious, but here goes. I am getting an exception thrown as a
I was right to be cautious, as I was missing the obvious.
result of executing line 52 of boost/trunk/boost/archive/impl/basic_binary_iarchive.ipp (yes I'm using trunk, but this happens with my 1.34.1 also)
The little program shown below causes it, the output of which is,
"std::exception: basic_string::resize"
Actually the real culprit was line 96 in boost/archive/impl/basic_binary_iprimitive.ipp I first saw this in a program that was streaming an archive over tcp using asio. For one reason and another I ended up producing an invalid archive (like the one in my example). The std::string::resize() exception threw me and sent me up the wrong path. The reason I am replying to this is that this exception may, or may not get thrown when you try to create an invalid archive, and of course if it does get thrown it doesn't really help much in diagnosing the problem. AFAICT there is no sensible way to detect an invalid archive until you try to deserialize it. However if this exception is thrown you can be fairly certain that your archive is invalid. I suggest then that it might be appropriate to translate this exception into one more meaningful to the user of the archive, something that indicated that the archive itself is likely to be invalid. There are many archive exceptions listed in the serialization documentation. <http://www.boost.org/libs/serialization/doc/archives.html#exceptions> This is obviously not one of them. It would be a good idea to either add this exception with a note or translate the actual exception into one meaningful to serialization archives, something like, invalid_archive. Jamie
participants (1)
-
Jamie Allsop