From 2f87ec0140f60c0609a389adc4e19c3466de9d96 Mon Sep 17 00:00:00 2001 From: Ben Jude Date: Sat, 24 Oct 2020 14:29:13 +0800 Subject: [PATCH] cross_system_copy_n: Dont attempt a copy if we're tyring to copy 0 elements Attempting to perform this copy with 0 elements caused a debug assertion when compiling with MSVC in debug mode. Fixes #1275 --- testing/vector.cu | 13 +++++++++++++ .../system/cuda/detail/internal/copy_cross_system.h | 13 +++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/testing/vector.cu b/testing/vector.cu index 8154b01c6c..297d426a2f 100644 --- a/testing/vector.cu +++ b/testing/vector.cu @@ -644,6 +644,19 @@ DECLARE_VECTOR_UNITTEST(TestVectorReserving) +template +void TestVectorUninitialisedCopy(void) +{ + thrust::device_vector v; + std::vector std_vector; + + v = std_vector; + + ASSERT_EQUAL(v.size(), 0); +} +DECLARE_VECTOR_UNITTEST(TestVectorUninitialisedCopy); + + template void TestVectorShrinkToFit(void) { diff --git a/thrust/system/cuda/detail/internal/copy_cross_system.h b/thrust/system/cuda/detail/internal/copy_cross_system.h index ab3b4e5bb7..e17d99ea45 100644 --- a/thrust/system/cuda/detail/internal/copy_cross_system.h +++ b/thrust/system/cuda/detail/internal/copy_cross_system.h @@ -100,12 +100,13 @@ namespace __copy { { typedef typename iterator_traits::value_type InputTy; - - trivial_device_copy(derived_cast(sys1), - derived_cast(sys2), - reinterpret_cast(thrust::raw_pointer_cast(&*result)), - reinterpret_cast(thrust::raw_pointer_cast(&*begin)), - n); + if (n > 0) { + trivial_device_copy(derived_cast(sys1), + derived_cast(sys2), + reinterpret_cast(thrust::raw_pointer_cast(&*result)), + reinterpret_cast(thrust::raw_pointer_cast(&*begin)), + n); + } return result + n; }