mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
fixed that the server crashes on too many snap items (Closes #317), optimised snapshot hashing
This commit is contained in:
parent
0b14286c7f
commit
8cdabb890f
|
@ -80,7 +80,7 @@ static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot)
|
||||||
for(int i = 0; i < pSnapshot->NumItems(); i++)
|
for(int i = 0; i < pSnapshot->NumItems(); i++)
|
||||||
{
|
{
|
||||||
int Key = pSnapshot->GetItem(i)->Key();
|
int Key = pSnapshot->GetItem(i)->Key();
|
||||||
int HashID = ((Key>>8)&0xf0) | (Key&0xf);
|
int HashID = ((Key>>12)&0xf0) | (Key&0xf);
|
||||||
if(pHashlist[HashID].m_Num != 64)
|
if(pHashlist[HashID].m_Num != 64)
|
||||||
{
|
{
|
||||||
pHashlist[HashID].m_aIndex[pHashlist[HashID].m_Num] = i;
|
pHashlist[HashID].m_aIndex[pHashlist[HashID].m_Num] = i;
|
||||||
|
@ -92,7 +92,7 @@ static void GenerateHash(CItemList *pHashlist, CSnapshot *pSnapshot)
|
||||||
|
|
||||||
static int GetItemIndexHashed(int Key, const CItemList *pHashlist)
|
static int GetItemIndexHashed(int Key, const CItemList *pHashlist)
|
||||||
{
|
{
|
||||||
int HashID = ((Key>>8)&0xf0) | (Key&0xf);
|
int HashID = ((Key>>12)&0xf0) | (Key&0xf);
|
||||||
for(int i = 0; i < pHashlist[HashID].m_Num; i++)
|
for(int i = 0; i < pHashlist[HashID].m_Num; i++)
|
||||||
{
|
{
|
||||||
if(pHashlist[HashID].m_aKeys[i] == Key)
|
if(pHashlist[HashID].m_aKeys[i] == Key)
|
||||||
|
@ -523,6 +523,14 @@ int CSnapshotBuilder::Finish(void *SpnapData)
|
||||||
|
|
||||||
void *CSnapshotBuilder::NewItem(int Type, int ID, int Size)
|
void *CSnapshotBuilder::NewItem(int Type, int ID, int Size)
|
||||||
{
|
{
|
||||||
|
if(m_DataSize + sizeof(CSnapshotItem) + Size >= CSnapshot::MAX_SIZE ||
|
||||||
|
m_NumItems+1 >= MAX_ITEMS)
|
||||||
|
{
|
||||||
|
dbg_assert(m_DataSize < CSnapshot::MAX_SIZE, "too much data");
|
||||||
|
dbg_assert(m_NumItems < MAX_ITEMS, "too many items");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
CSnapshotItem *pObj = (CSnapshotItem *)(m_aData + m_DataSize);
|
CSnapshotItem *pObj = (CSnapshotItem *)(m_aData + m_DataSize);
|
||||||
|
|
||||||
mem_zero(pObj, sizeof(CSnapshotItem) + Size);
|
mem_zero(pObj, sizeof(CSnapshotItem) + Size);
|
||||||
|
@ -530,9 +538,6 @@ void *CSnapshotBuilder::NewItem(int Type, int ID, int Size)
|
||||||
m_aOffsets[m_NumItems] = m_DataSize;
|
m_aOffsets[m_NumItems] = m_DataSize;
|
||||||
m_DataSize += sizeof(CSnapshotItem) + Size;
|
m_DataSize += sizeof(CSnapshotItem) + Size;
|
||||||
m_NumItems++;
|
m_NumItems++;
|
||||||
|
|
||||||
dbg_assert(m_DataSize < CSnapshot::MAX_SIZE, "too much data");
|
|
||||||
dbg_assert(m_NumItems < MAX_ITEMS, "too many items");
|
|
||||||
|
|
||||||
return pObj->Data();
|
return pObj->Data();
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ class CSnapshotBuilder
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
MAX_ITEMS = 1024*2
|
MAX_ITEMS = 1024
|
||||||
};
|
};
|
||||||
|
|
||||||
char m_aData[CSnapshot::MAX_SIZE];
|
char m_aData[CSnapshot::MAX_SIZE];
|
||||||
|
|
Loading…
Reference in a new issue