From 07f078640ae742ca7676f5f6dcbc844698b4b446 Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 2 Feb 2023 17:41:17 -0800 Subject: [PATCH] CopyBuffer: Skip Zero Elements Avoid operating on invalid memory in `CopyBuffer` if the operation is zero elements. --- source/adios2/helper/adiosMemory.inl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/adios2/helper/adiosMemory.inl b/source/adios2/helper/adiosMemory.inl index 41a5d765aa..556d820ccd 100644 --- a/source/adios2/helper/adiosMemory.inl +++ b/source/adios2/helper/adiosMemory.inl @@ -146,6 +146,11 @@ template void CopyToBuffer(std::vector &buffer, size_t &position, const T *source, const size_t elements) noexcept { + if (elements == 0) + { + return; + } + const char *src = reinterpret_cast(source); std::copy(src, src + elements * sizeof(T), buffer.begin() + position); position += elements * sizeof(T);