Opened 16 years ago

Closed 16 years ago

#702 closed Bugs (Fixed)

serializing empty vectors triggers STL assertion failure (VC

Reported by: pintaric Owned by: Matthias Troyer
Milestone: Component: serialization
Version: None Severity:
Keywords: Cc:

Description

Serializing empty vectors triggers an STL assertion
failure (VC++ 8.0).

Test case:
==========

typedef std::vector<int> vec_t;
vec_t v; // empty vector
{
  std::ofstream ofs("test.dat");
  boost::archive::binary_oarchive oa(ofs);
  oa << v; // triggers runtime assertion
}

The assertion is caused by line 31 in
serialization/detail/get_data.hpp (note that vector v
is empty):
[0031]  return &(v[0]);


Proposed fix:
=============

Index: oarchive.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/archive/array/oarchive.hpp,v
retrieving revision 1.3
diff -r1.3 oarchive.hpp
73c73
<     * this->This() <<
serialization::make_array(serialization::detail::get_data(t),t.size());
---
>     if(count) * this->This() <<
serialization::make_array(serialization::detail::get_data(t),t.size());


Index: iarchive.hpp
===================================================================
RCS file:
/cvsroot/boost/boost/boost/archive/array/iarchive.hpp,v
retrieving revision 1.3
diff -r1.3 iarchive.hpp
77c77
<     * this->This() >>
serialization::make_array(serialization::detail::get_data(t),t.size());
---
>     if(count) * this->This() >>
serialization::make_array(serialization::detail::get_data(t),t.size());

Change History (1)

comment:1 by Matthias Troyer, 16 years ago

Status: assignedclosed
Note: See TracTickets for help on using tickets.