Skip to content

Commit

Permalink
mpi::detail::c_data needs to check for empty vectors
Browse files Browse the repository at this point in the history
If the standard library is configured to do range checks (-D _GLIBCXX_ASSERTIONS), accessing the zeroth element of a vector to get its address triggers an assertion.
  • Loading branch information
mkuron authored Feb 14, 2019
1 parent 569bfa3 commit dc70843
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/boost/mpi/detail/antiques.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace detail {
// serve as an incentive to get rid of this when those compilers
// are dropped.
template <typename T, typename A>
T* c_data(std::vector<T,A>& v) { return &(v[0]); }
T* c_data(std::vector<T,A>& v) { if (v.empty()) return NULL; return &(v[0]); }

template <typename T, typename A>
T const* c_data(std::vector<T,A> const& v) { return &(v[0]); }
T const* c_data(std::vector<T,A> const& v) { if (v.empty()) return NULL; return &(v[0]); }

// Some old MPI implementation (OpenMPI 1.6 for example) have non
// conforming API w.r.t. constness.
Expand Down

0 comments on commit dc70843

Please sign in to comment.