|
Boost Users : |
Subject: [Boost-users] boost.serializaion off by one error
From: . lai (linhualai_at_[hidden])
Date: 2011-04-25 23:25:51
Hi all:
Recently i come up with a problem in boost.serializaion when
serializing primitives.
with the following code, the output is:
1
0
input stream error
But what i expect is:
1
input stream error
test code:
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <sstream>
#include <iostream>
int main(int argc, char *argv[])
{
std::stringstream stream;
{
boost::archive::text_oarchive oa(stream);
int i = 1;
oa << i;
}
try
{
boost::archive::text_iarchive ia(stream);
int i = 0;
ia >> i;
std::cout << i << std::endl;
i = 0;
ia >> i;
std::cout << i << std::endl;
i = 0;
ia >> i;
std::cout << i << std::endl;
}catch(boost::archive::archive_exception& ex){
std::cout << ex.what() << std::endl;
}
return 0;
}
the exception is threw in /usr/include/boost/archive/basic_text_iprimitive.hpp:
basic_text_iprimitive::
template<class T>
void load(T & t)
{
if(! is.fail()){
is >> t; //HERE SHOULD TEST IF READ IS SUCCUSSFULL
return;
}
boost::serialization::throw_exception(
archive_exception(archive_exception::input_stream_error)
);
}
In the function basic_text_iprimitive::load(T t), when T is a
primitive, and is >> t fails, there is no exception threw, where there
should.
The same problem exsits in binary archive and text archive.
Is it a bug or a feature? would it be fixed?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net