Skip to content

Commit

Permalink
CopyBuffer: Skip Zero Elements
Browse files Browse the repository at this point in the history
Avoid operating on invalid memory in `CopyBuffer` if the operation
is zero elements.
  • Loading branch information
ax3l authored and vicentebolea committed Feb 14, 2023
1 parent 8ce1caf commit 07f0786
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/adios2/helper/adiosMemory.inl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ template <class T>
void CopyToBuffer(std::vector<char> &buffer, size_t &position, const T *source,
const size_t elements) noexcept
{
if (elements == 0)
{
return;
}

const char *src = reinterpret_cast<const char *>(source);
std::copy(src, src + elements * sizeof(T), buffer.begin() + position);
position += elements * sizeof(T);
Expand Down

0 comments on commit 07f0786

Please sign in to comment.