From 190f63854bae3b95e5ca0193c4086c662bc02a10 Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Mon, 5 Oct 2020 10:47:29 +0200 Subject: [PATCH] CustomMemoryBuffer: only memcpy when not `nullptr` --- src/cuda/communication/CustomMemoryBuffer.impl.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cuda/communication/CustomMemoryBuffer.impl.h b/src/cuda/communication/CustomMemoryBuffer.impl.h index 377ba4bd3..5bf1ac8c1 100644 --- a/src/cuda/communication/CustomMemoryBuffer.impl.h +++ b/src/cuda/communication/CustomMemoryBuffer.impl.h @@ -83,7 +83,10 @@ namespace communication { newBegin = reinterpret_cast<ElementType *>(Allocator::allocate( newSize )); - Allocator::memcpy( newBegin, begin_, size_t(end_ - begin_) ); + // memcpy: If either dest or src is an invalid or null pointer, the behavior is undefined, even if count is zero. + if(begin_) { + Allocator::memcpy( newBegin, begin_, size_t(end_ - begin_) ); + } std::swap( begin_, newBegin ); if( newBegin != nullptr ) -- GitLab