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
#include
#include
#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(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 >::operator()(boost::archive::text_iarchive&, std::vector&) (collections_load_imp.hpp:54)
...
==10018== by 0x80506A7: boost::archive::text_iarchive& boost::archive::detail::interface_iarchiveboost::archive::text_iarchive::operator>> >(std::vector&) (interface_iarchive.hpp:76)
==10018== by 0x804B7F2: main (serialize_bug.cpp:40)
--
Jonathan Cooper MSN: msn@jonc.me.uk www: jonc.me.uk/
I never learned anything while I was talking - Larry King