Skip to content

Commit

Permalink
Engine: fix serializing of zero-length dynamic array
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Feb 27, 2025
1 parent 681d19c commit 5f68ada
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Engine/ac/dynobj/cc_dynamicarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CCDynamicArray::Serialize(const void *address, Stream *out)
const Header &hdr = GetHeader(address);
out->WriteInt32(hdr.TypeID);
out->WriteInt32(hdr.ElemCount);
out->WriteInt32(hdr.TotalSize / hdr.ElemCount); // elem size
out->WriteInt32(hdr.ElemCount > 0 ? (hdr.TotalSize / hdr.ElemCount) : 0); // elem size
out->Write(address, hdr.TotalSize); // elements
}

Expand Down Expand Up @@ -142,7 +142,7 @@ void CCDynamicArray::TraverseRefs(void *address, PfnTraverseRefOp traverse_op)
{ // there are managed pointers inside!
const uint8_t *elem_ptr = static_cast<const uint8_t*>(address);
// For each array element...
const uint32_t el_size = hdr.TotalSize / hdr.ElemCount;
const uint32_t el_size = hdr.ElemCount > 0 ? (hdr.TotalSize / hdr.ElemCount) : 0;
for (uint32_t i = 0; i < hdr.ElemCount; ++i, elem_ptr += el_size)
{
// ..subref each managed pointer found inside
Expand Down

0 comments on commit 5f68ada

Please sign in to comment.