mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
Merge #6252
6252: Use distinct error return codes for `CSnapshotDelta::UnpackDelta` r=heinrich5991 a=Robyt3 Use a different error code for every return statement, so it's easier to determine why unpacking a delta failed. The codes are grouped by the first digit of the error code: - `-1xx`: not enough data to read - `-2xx`: value is invalid - `-3xx`: could not build snapshot item <!-- What is the motivation for the changes of this pull request? --> <!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. --> ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
7d4fabd7f3
|
@ -372,10 +372,10 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, const void *pS
|
|||
// unpack deleted stuff
|
||||
int *pDeleted = pData;
|
||||
if(pDelta->m_NumDeletedItems < 0)
|
||||
return -1;
|
||||
return -201;
|
||||
pData += pDelta->m_NumDeletedItems;
|
||||
if(pData > pEnd)
|
||||
return -1;
|
||||
return -101;
|
||||
|
||||
// copy all non deleted stuff
|
||||
for(int i = 0; i < pFrom->NumItems(); i++)
|
||||
|
@ -396,7 +396,7 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, const void *pS
|
|||
{
|
||||
void *pObj = Builder.NewItem(pFromItem->Type(), pFromItem->ID(), ItemSize);
|
||||
if(!pObj)
|
||||
return -4;
|
||||
return -301;
|
||||
|
||||
// keep it
|
||||
mem_copy(pObj, pFromItem->Data(), ItemSize);
|
||||
|
@ -407,15 +407,15 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, const void *pS
|
|||
for(int i = 0; i < pDelta->m_NumUpdateItems; i++)
|
||||
{
|
||||
if(pData + 2 > pEnd)
|
||||
return -1;
|
||||
return -102;
|
||||
|
||||
const int Type = *pData++;
|
||||
if(Type < 0 || Type > CSnapshot::MAX_TYPE)
|
||||
return -3;
|
||||
return -202;
|
||||
|
||||
const int ID = *pData++;
|
||||
if(ID < 0 || ID > CSnapshot::MAX_ID)
|
||||
return -3;
|
||||
return -203;
|
||||
|
||||
int ItemSize;
|
||||
if(Type < MAX_NETOBJSIZES && m_aItemSizes[Type])
|
||||
|
@ -423,14 +423,14 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, const void *pS
|
|||
else
|
||||
{
|
||||
if(pData + 1 > pEnd)
|
||||
return -2;
|
||||
return -103;
|
||||
if(*pData < 0 || *pData > INT_MAX / 4)
|
||||
return -3;
|
||||
return -204;
|
||||
ItemSize = (*pData++) * 4;
|
||||
}
|
||||
|
||||
if(ItemSize < 0 || RangeCheck(pEnd, pData, ItemSize))
|
||||
return -3;
|
||||
return -205;
|
||||
|
||||
const int Key = (Type << 16) | ID;
|
||||
|
||||
|
@ -440,14 +440,14 @@ int CSnapshotDelta::UnpackDelta(CSnapshot *pFrom, CSnapshot *pTo, const void *pS
|
|||
pNewData = (int *)Builder.NewItem(Type, ID, ItemSize);
|
||||
|
||||
if(!pNewData)
|
||||
return -4;
|
||||
return -302;
|
||||
|
||||
const int FromIndex = pFrom->GetItemIndex(Key);
|
||||
if(FromIndex != -1)
|
||||
{
|
||||
// we got an update so we need to apply the diff
|
||||
if(!UndiffItem(pFrom->GetItem(FromIndex)->Data(), pData, pNewData, ItemSize / 4, &m_aSnapshotDataRate[Type]))
|
||||
return -3;
|
||||
return -206;
|
||||
}
|
||||
else // no previous, just copy the pData
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue