Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid access of front element in empty vectors #119

Merged
merged 4 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 148 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,37 @@ matrix:
include:
- os: linux
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03
addons:
apt:
packages:
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=11
addons:
apt:
packages:
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: g++-4.4
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98
addons:
apt:
packages:
- g++-4.4
- libopenmpi-dev
- openmpi-bin
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-4.4
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=0x
addons:
apt:
packages:
Expand All @@ -45,9 +66,22 @@ matrix:
sources:
- ubuntu-toolchain-r-test


- os: linux
compiler: g++-4.6
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03
addons:
apt:
packages:
- g++-4.6
- libopenmpi-dev
- openmpi-bin
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-4.6
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=0x
addons:
apt:
packages:
Expand All @@ -59,7 +93,19 @@ matrix:

- os: linux
compiler: g++-5
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=11,14
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=11
addons:
apt:
packages:
- g++-5
- libopenmpi-dev
- openmpi-bin
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-5
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=14
addons:
apt:
packages:
Expand All @@ -71,7 +117,7 @@ matrix:

- os: linux
compiler: g++-6
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=11,14
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=11
addons:
apt:
packages:
Expand All @@ -81,9 +127,33 @@ matrix:
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-6
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=14
addons:
apt:
packages:
- g++-6
- libopenmpi-dev
- openmpi-bin
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-7
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=14
addons:
apt:
packages:
- g++-7
- libopenmpi-dev
- openmpi-bin
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-7
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=14,17
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=17
addons:
apt:
packages:
Expand All @@ -95,7 +165,19 @@ matrix:

- os: linux
compiler: g++-8
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=14,17
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=14
addons:
apt:
packages:
- g++-8
- libopenmpi-dev
- openmpi-bin
sources:
- ubuntu-toolchain-r-test

- os: linux
compiler: g++-8
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=17
addons:
apt:
packages:
Expand All @@ -107,16 +189,73 @@ matrix:

- os: linux
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03
addons:
apt:
packages:
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=11
addons:
apt:
packages:
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=14
addons:
apt:
packages:
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=1z
addons:
apt:
packages:
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++-libc++
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03
addons:
apt:
packages:
- libc++-dev
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++-libc++
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=11
addons:
apt:
packages:
- libc++-dev
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++-libc++
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=14
addons:
apt:
packages:
- libc++-dev
- libopenmpi-dev
- openmpi-bin

- os: linux
compiler: clang++-libc++
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z
env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=1z
addons:
apt:
packages:
Expand Down
2 changes: 1 addition & 1 deletion include/boost/mpi/collectives/all_reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace detail {
// implementation in this case.
// it's not clear how/if we can avoid the copy.
std::vector<T> tmp_in( out_values, out_values + n);
reduce(comm, &(tmp_in[0]), n, out_values, op, 0);
reduce(comm, detail::c_data(tmp_in), n, out_values, op, 0);
} else {
reduce(comm, in_values, n, out_values, op, 0);
}
Expand Down
12 changes: 6 additions & 6 deletions include/boost/mpi/collectives/all_to_all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ namespace detail {

// Transmit the actual data
BOOST_MPI_CHECK_RESULT(MPI_Alltoallv,
(&outgoing[0], &send_sizes[0],
&send_disps[0], MPI_PACKED,
&incoming[0], &recv_sizes[0],
&recv_disps[0], MPI_PACKED,
(detail::c_data(outgoing), detail::c_data(send_sizes),
detail::c_data(send_disps), MPI_PACKED,
detail::c_data(incoming), detail::c_data(recv_sizes),
detail::c_data(recv_disps), MPI_PACKED,
comm));

// Deserialize data from the iarchive
Expand Down Expand Up @@ -126,7 +126,7 @@ all_to_all(const communicator& comm, const std::vector<T>& in_values,
{
BOOST_ASSERT((int)in_values.size() == comm.size());
out_values.resize(comm.size());
::boost::mpi::all_to_all(comm, &in_values[0], &out_values[0]);
::boost::mpi::all_to_all(comm, detail::c_data(in_values), detail::c_data(out_values));
}

template<typename T>
Expand All @@ -143,7 +143,7 @@ all_to_all(const communicator& comm, const std::vector<T>& in_values, int n,
{
BOOST_ASSERT((int)in_values.size() == comm.size() * n);
out_values.resize(comm.size() * n);
::boost::mpi::all_to_all(comm, &in_values[0], n, &out_values[0]);
::boost::mpi::all_to_all(comm, detail::c_data(in_values), n, detail::c_data(out_values));
}

} } // end namespace boost::mpi
Expand Down
8 changes: 4 additions & 4 deletions include/boost/mpi/collectives/gatherv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ gatherv(const communicator& comm, const T* in_values, int in_size,
{
if (comm.rank() == root)
detail::gatherv_impl(comm, in_values, in_size,
out_values, &sizes[0], &displs[0],
out_values, detail::c_data(sizes), detail::c_data(displs),
root, is_mpi_datatype<T>());
else
detail::gatherv_impl(comm, in_values, in_size, root, is_mpi_datatype<T>());
Expand All @@ -99,7 +99,7 @@ gatherv(const communicator& comm, const std::vector<T>& in_values,
T* out_values, const std::vector<int>& sizes, const std::vector<int>& displs,
int root)
{
::boost::mpi::gatherv(comm, &in_values[0], in_values.size(), out_values, sizes, displs, root);
::boost::mpi::gatherv(comm, detail::c_data(in_values), in_values.size(), out_values, sizes, displs, root);
}

template<typename T>
Expand All @@ -113,7 +113,7 @@ template<typename T>
void gatherv(const communicator& comm, const std::vector<T>& in_values, int root)
{
BOOST_ASSERT(comm.rank() != root);
detail::gatherv_impl(comm, &in_values[0], in_values.size(), root, is_mpi_datatype<T>());
detail::gatherv_impl(comm, detail::c_data(in_values), in_values.size(), root, is_mpi_datatype<T>());
}

///////////////////////
Expand All @@ -139,7 +139,7 @@ void
gatherv(const communicator& comm, const std::vector<T>& in_values,
T* out_values, const std::vector<int>& sizes, int root)
{
::boost::mpi::gatherv(comm, &in_values[0], in_values.size(), out_values, sizes, root);
::boost::mpi::gatherv(comm, detail::c_data(in_values), in_values.size(), out_values, sizes, root);
}

} } // end namespace boost::mpi
Expand Down
4 changes: 2 additions & 2 deletions include/boost/mpi/collectives/reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void
reduce(const communicator & comm, std::vector<T> const & in_values, Op op,
int root)
{
reduce(comm, &in_values.front(), in_values.size(), op, root);
reduce(comm, detail::c_data(in_values), in_values.size(), op, root);
}

template<typename T, typename Op>
Expand All @@ -344,7 +344,7 @@ reduce(const communicator & comm, std::vector<T> const & in_values,
std::vector<T> & out_values, Op op, int root)
{
if (root == comm.rank()) out_values.resize(in_values.size());
reduce(comm, &in_values.front(), in_values.size(), &out_values.front(), op,
reduce(comm, detail::c_data(in_values), in_values.size(), detail::c_data(out_values), op,
root);
}

Expand Down
2 changes: 1 addition & 1 deletion include/boost/mpi/collectives/scatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void
scatter(const communicator& comm, const std::vector<T>& in_values,
T* out_values, int n, int root)
{
::boost::mpi::scatter(comm, &in_values[0], out_values, n, root);
::boost::mpi::scatter(comm, detail::c_data(in_values), out_values, n, root);
}

template<typename T>
Expand Down
4 changes: 2 additions & 2 deletions include/boost/mpi/collectives/scatterv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void
scatterv(const communicator& comm, const std::vector<T>& in_values,
const std::vector<int>& sizes, T* out_values, int root)
{
::boost::mpi::scatterv(comm, &in_values[0], sizes, out_values, root);
::boost::mpi::scatterv(comm, detail::c_data(in_values), sizes, out_values, root);
}

template<typename T>
Expand All @@ -159,7 +159,7 @@ void
scatterv(const communicator& comm, const std::vector<T>& in_values,
T* out_values, int out_size, int root)
{
::boost::mpi::scatterv(comm, &in_values[0], out_values, out_size, root);
::boost::mpi::scatterv(comm, detail::c_data(in_values), out_values, out_size, root);
}

} } // end namespace boost::mpi
Expand Down
4 changes: 2 additions & 2 deletions include/boost/mpi/detail/binary_buffer_iprimitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ class BOOST_MPI_DECL binary_buffer_iprimitive

void* address ()
{
return &buffer_.front();
return detail::c_data(buffer_);
}

void const* address () const
{
return &buffer_.front();
return detail::c_data(buffer_);
}

const std::size_t& size() const
Expand Down
2 changes: 1 addition & 1 deletion include/boost/mpi/detail/binary_buffer_oprimitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BOOST_MPI_DECL binary_buffer_oprimitive

void const * address() const
{
return &buffer_.front();
return detail::c_data(buffer_);
}

const std::size_t& size() const
Expand Down
2 changes: 1 addition & 1 deletion include/boost/mpi/detail/mpi_datatype_primitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class mpi_datatype_primitive
template <class T>
static T* get_data(std::vector<T>& v)
{
return v.empty() ? 0 : &(v[0]);
return detail::c_data(v);
}

std::vector<MPI_Aint> addresses;
Expand Down
4 changes: 2 additions & 2 deletions include/boost/mpi/detail/packed_iprimitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class BOOST_MPI_DECL packed_iprimitive

void* address ()
{
return &buffer_[0];
return detail::c_data(buffer_);
}

void const* address () const
{
return &buffer_[0];
return detail::c_data(buffer_);
}

const std::size_t& size() const
Expand Down
Loading