Skip to content

Commit 5f68ada

Browse files
committed
Engine: fix serializing of zero-length dynamic array
1 parent 681d19c commit 5f68ada

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Engine/ac/dynobj/cc_dynamicarray.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void CCDynamicArray::Serialize(const void *address, Stream *out)
5555
const Header &hdr = GetHeader(address);
5656
out->WriteInt32(hdr.TypeID);
5757
out->WriteInt32(hdr.ElemCount);
58-
out->WriteInt32(hdr.TotalSize / hdr.ElemCount); // elem size
58+
out->WriteInt32(hdr.ElemCount > 0 ? (hdr.TotalSize / hdr.ElemCount) : 0); // elem size
5959
out->Write(address, hdr.TotalSize); // elements
6060
}
6161

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

0 commit comments

Comments
 (0)