mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 05:58:19 +00:00
Do not add snap item if extended item type could not be added
The `CSnapshotBuilder::AddExtendedItemType` function can fail if the snapshot is already full. Previously, this was not handled, leading to `m_aExtendedItemTypes` being updated inconsistently with the real extended item types and the snap item being added without the extended item type. Now, the snap item is not added if its extended item type could not be added.
This commit is contained in:
parent
67068ade90
commit
9a380ff199
|
@ -767,17 +767,22 @@ int CSnapshotBuilder::GetTypeFromIndex(int Index) const
|
|||
return CSnapshot::MAX_TYPE - Index;
|
||||
}
|
||||
|
||||
void CSnapshotBuilder::AddExtendedItemType(int Index)
|
||||
bool CSnapshotBuilder::AddExtendedItemType(int Index)
|
||||
{
|
||||
dbg_assert(0 <= Index && Index < m_NumExtendedItemTypes, "index out of range");
|
||||
int TypeId = m_aExtendedItemTypes[Index];
|
||||
CUuid Uuid = g_UuidManager.GetUuid(TypeId);
|
||||
int *pUuidItem = (int *)NewItem(0, GetTypeFromIndex(Index), sizeof(Uuid)); // NETOBJTYPE_EX
|
||||
if(pUuidItem)
|
||||
int *pUuidItem = static_cast<int *>(NewItem(0, GetTypeFromIndex(Index), sizeof(CUuid))); // NETOBJTYPE_EX
|
||||
if(pUuidItem == nullptr)
|
||||
{
|
||||
for(size_t i = 0; i < sizeof(CUuid) / sizeof(int32_t); i++)
|
||||
pUuidItem[i] = bytes_be_to_uint(&Uuid.m_aData[i * sizeof(int32_t)]);
|
||||
return false;
|
||||
}
|
||||
|
||||
const int TypeId = m_aExtendedItemTypes[Index];
|
||||
const CUuid Uuid = g_UuidManager.GetUuid(TypeId);
|
||||
for(size_t i = 0; i < sizeof(CUuid) / sizeof(int32_t); i++)
|
||||
{
|
||||
pUuidItem[i] = bytes_be_to_uint(&Uuid.m_aData[i * sizeof(int32_t)]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int CSnapshotBuilder::GetExtendedItemTypeIndex(int TypeId)
|
||||
|
@ -793,8 +798,12 @@ int CSnapshotBuilder::GetExtendedItemTypeIndex(int TypeId)
|
|||
int Index = m_NumExtendedItemTypes;
|
||||
m_NumExtendedItemTypes++;
|
||||
m_aExtendedItemTypes[Index] = TypeId;
|
||||
AddExtendedItemType(Index);
|
||||
return Index;
|
||||
if(AddExtendedItemType(Index))
|
||||
{
|
||||
return Index;
|
||||
}
|
||||
m_NumExtendedItemTypes--;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *CSnapshotBuilder::NewItem(int Type, int Id, int Size)
|
||||
|
@ -816,11 +825,15 @@ void *CSnapshotBuilder::NewItem(int Type, int Id, int Size)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool Extended = false;
|
||||
if(Type >= OFFSET_UUID)
|
||||
const bool Extended = Type >= OFFSET_UUID;
|
||||
if(Extended)
|
||||
{
|
||||
Extended = true;
|
||||
Type = GetTypeFromIndex(GetExtendedItemTypeIndex(Type));
|
||||
const int ExtendedItemTypeIndex = GetExtendedItemTypeIndex(Type);
|
||||
if(ExtendedItemTypeIndex == -1)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
Type = GetTypeFromIndex(ExtendedItemTypeIndex);
|
||||
}
|
||||
|
||||
CSnapshotItem *pObj = (CSnapshotItem *)(m_aData + m_DataSize);
|
||||
|
|
|
@ -158,7 +158,7 @@ class CSnapshotBuilder
|
|||
int m_aExtendedItemTypes[MAX_EXTENDED_ITEM_TYPES];
|
||||
int m_NumExtendedItemTypes;
|
||||
|
||||
void AddExtendedItemType(int Index);
|
||||
bool AddExtendedItemType(int Index);
|
||||
int GetExtendedItemTypeIndex(int TypeId);
|
||||
int GetTypeFromIndex(int Index) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue