diff --git a/src/OpenMesh/Core/IO/SR_binary_spec.hh b/src/OpenMesh/Core/IO/SR_binary_spec.hh index e3cb5938..bc922727 100644 --- a/src/OpenMesh/Core/IO/SR_binary_spec.hh +++ b/src/OpenMesh/Core/IO/SR_binary_spec.hh @@ -188,11 +188,12 @@ SIMPLE_BINARY(unsigned long); static size_t size_of(const value_type&) { return size_of(); } \ static std::string string_for_value_type(void) { return get_string_for_type(value_type()); } \ static size_t store( std::ostream& _os, const value_type& _val, \ - bool _swap=false) { \ + bool _swap=false) { \ value_type tmp = _val; \ size_t i, b = size_of(_val), N = value_type::size_; \ - if (_swap) for (i=0; i > { bytes += binary::store( _os, N, _swap ); } if (_swap) - bytes += std::accumulate( _v.begin(), _v.end(), static_cast(0), - FunctorStore(_os,_swap) ); + bytes += std::accumulate( _v.begin(), _v.end(), static_cast(0), + FunctorStore(_os,_swap) ); else { - auto bytes_of_vec = size_of(_v, false); - bytes += bytes_of_vec; - _os.write( reinterpret_cast(&_v[0]), bytes_of_vec); + auto bytes_of_vec = size_of(_v, false); + bytes += bytes_of_vec; + if (_v.size() > 0) + _os.write( reinterpret_cast(&_v[0]), bytes_of_vec); } return _os.good() ? bytes : 0; } @@ -395,7 +397,8 @@ struct binary< std::vector< T > > { { auto bytes_of_vec = size_of(_v, false); bytes += bytes_of_vec; - _is.read( reinterpret_cast(&_v[0]), bytes_of_vec ); + if (_v.size() > 0) + _is.read( reinterpret_cast(&_v[0]), bytes_of_vec ); } return _is.good() ? bytes : 0; }