|
Boost Users : |
From: Jonathan Cooper (jonathan.cooper_at_[hidden])
Date: 2007-03-21 07:54:05
Hi.
In using valgrind to run memory tests of our software, we've been getting
'Conditional jump or move depends on uninitialised value(s)' errors which
appear to be caused by Boost's serialization library. Specifically, they
occur on loading a std::vector<double> from a text archive. A simple
test program which demonstrates this behaviour is shown below, together
with a snippet from valgrind's output.
Incidentally, deserializing std::vector<bool> does not have this problem,
and specializing boost::serialization::{save,load} for vector as for bool
makes the problem go away.
Any ideas?
Jonathan.
Boost version: 1.33.1
Valgrind version: 3.2.1
System: Fedora Core 6
g++ (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
Test program, which compiles and runs as expected:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <fstream>
#include <cmath>
#include <cassert>
int main(void)
{
std::string archive_filename("simple_vars.arch");
// Create an ouput archive
{
std::ofstream ofs(archive_filename.c_str());
boost::archive::text_oarchive output_arch(ofs);
std::vector<double> doubles(3);
doubles[0] = 1.1;
doubles[1] = 1.2;
doubles[2] = 1.3;
// cast to const and write
output_arch << static_cast<const std::vector<double>&>(doubles);
}
{
// Create an input archive
std::ifstream ifs(archive_filename.c_str(), std::ios::binary);
boost::archive::text_iarchive input_arch(ifs);
std::vector<double> doubles;
// read the archive
input_arch >> doubles;
// test values
assert(doubles.size() == 3u);
assert(fabs(doubles[0] - 1.1) < 1e-12);
assert(fabs(doubles[1] - 1.2) < 1e-12);
assert(fabs(doubles[2] - 1.3) < 1e-12);
}
return 0;
}
Excerpt from valgrind stack trace:
==10018== Conditional jump or move depends on uninitialised value(s)
==10018== at 0x403C0ED: boost::archive::detail::basic_iarchive::reset_object_address(void const*, void const*) (in /usr/lib/libboost_serialization.so.1.33.1)
==10018== by 0x804E23E: boost::serialization::stl::archive_input_seq<boost::archive::text_iarchive, std::vector<double, std::allocator<double> > >::operator()(boost::archive::text_iarchive&, std::vector<double, std::allocator<double> >&) (collections_load_imp.hpp:54)
...
==10018== by 0x80506A7: boost::archive::text_iarchive& boost::archive::detail::interface_iarchive<boost::archive::text_iarchive>::operator>><std::vector<double, std::allocator<double> > >(std::vector<double, std::allocator<double> >&) (interface_iarchive.hpp:76)
==10018== by 0x804B7F2: main (serialize_bug.cpp:40)
-- Jonathan Cooper MSN: msn_at_[hidden] www: jonc.me.uk/ I never learned anything while I was talking - Larry King
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