Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
cross_system_copy_n: Dont attempt a copy if we're tyring to copy 0 el…
Browse files Browse the repository at this point in the history
…ements

Attempting to perform this copy with 0 elements caused a debug assertion when compiling with MSVC in debug mode.

Fixes #1275
  • Loading branch information
bjude authored and alliepiper committed Nov 5, 2020
1 parent 5df7084 commit 1c4f25d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 13 additions & 0 deletions testing/vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,19 @@ DECLARE_VECTOR_UNITTEST(TestVectorReserving)



template <class Vector>
void TestVectorUninitialisedCopy(void)
{
thrust::device_vector<int> v;
std::vector<int> std_vector;

v = std_vector;

ASSERT_EQUAL(v.size(), static_cast<size_t>(0));
}
DECLARE_VECTOR_UNITTEST(TestVectorUninitialisedCopy);


template <class Vector>
void TestVectorShrinkToFit(void)
{
Expand Down
13 changes: 7 additions & 6 deletions thrust/system/cuda/detail/internal/copy_cross_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ namespace __copy {

{
typedef typename iterator_traits<InputIt>::value_type InputTy;

trivial_device_copy(derived_cast(sys1),
derived_cast(sys2),
reinterpret_cast<InputTy*>(thrust::raw_pointer_cast(&*result)),
reinterpret_cast<InputTy const*>(thrust::raw_pointer_cast(&*begin)),
n);
if (n > 0) {
trivial_device_copy(derived_cast(sys1),
derived_cast(sys2),
reinterpret_cast<InputTy*>(thrust::raw_pointer_cast(&*result)),
reinterpret_cast<InputTy const*>(thrust::raw_pointer_cast(&*begin)),
n);
}

return result + n;
}
Expand Down

0 comments on commit 1c4f25d

Please sign in to comment.