Skip to content

Commit

Permalink
Avoid memmove if there is nothing to move
Browse files Browse the repository at this point in the history
To avoid UD with nullptr passed to memmove.
  • Loading branch information
shahor02 committed Jan 14, 2024
1 parent 2bf1652 commit 79a0fe0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion GPU/Utils/FlatObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ T* resizeArray(T*& ptr, int oldSize, int newSize, T* newPtr = nullptr)
newPtr = new T[newSize];
}
int mcp = std::min(newSize, oldSize);
std::memmove(newPtr, ptr, mcp * sizeof(T));
if (mcp) {
assert(ptr);
std::memmove(newPtr, ptr, mcp * sizeof(T));
}
if (newSize > oldSize) {
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T));
}
Expand Down

0 comments on commit 79a0fe0

Please sign in to comment.