mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Handle snap ID potentially being out of range
According to cppchecker's `arrayIndexOutOfBoundsCond` error: ``` src\engine\server\server.cpp:117:19: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond] dbg_assert(m_aIDs[ID].m_State == ID_ALLOCATED, "id is not allocated"); ^ src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant if(ID < 0) ^ src\engine\server\server.cpp:117:19: note: Array index out of bounds dbg_assert(m_aIDs[ID].m_State == ID_ALLOCATED, "id is not allocated"); ^ src\engine\server\server.cpp:120:8: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond] m_aIDs[ID].m_State = ID_TIMED; ^ src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant if(ID < 0) ^ src\engine\server\server.cpp:120:8: note: Array index out of bounds m_aIDs[ID].m_State = ID_TIMED; ^ src\engine\server\server.cpp:121:8: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond] m_aIDs[ID].m_Timeout = time_get() + time_freq() * 5; ^ src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant if(ID < 0) ^ src\engine\server\server.cpp:121:8: note: Array index out of bounds m_aIDs[ID].m_Timeout = time_get() + time_freq() * 5; ^ src\engine\server\server.cpp:122:8: warning: Either the condition 'ID<0' is redundant or the array 'm_aIDs[32768]' is accessed at index 32768, which is out of bounds. [arrayIndexOutOfBoundsCond] m_aIDs[ID].m_Next = -1; ^ src\engine\server\server.cpp:115:8: note: Assuming that condition 'ID<0' is not redundant if(ID < 0) ^ src\engine\server\server.cpp:122:8: note: Array index out of bounds m_aIDs[ID].m_Next = -1; ^ ```
This commit is contained in:
parent
d2868325b6
commit
2115c12282
|
@ -115,6 +115,7 @@ void CSnapIDPool::FreeID(int ID)
|
|||
{
|
||||
if(ID < 0)
|
||||
return;
|
||||
dbg_assert((size_t)ID < std::size(m_aIDs), "id is out of range");
|
||||
dbg_assert(m_aIDs[ID].m_State == ID_ALLOCATED, "id is not allocated");
|
||||
|
||||
m_InUsage--;
|
||||
|
|
Loading…
Reference in a new issue