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 committed Feb 3, 2023
1 parent 98bef0e commit d250d75
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 d250d75

Please sign in to comment.