mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #3051
3051: Fix some undefined behaviour r=heinrich5991 a=def- Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
91619b9886
|
@ -1872,7 +1872,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
|
|||
int GameTick = Unpacker.GetInt();
|
||||
int DeltaTick = GameTick - Unpacker.GetInt();
|
||||
int PartSize = 0;
|
||||
int Crc = 0;
|
||||
unsigned int Crc = 0;
|
||||
int CompleteSize = 0;
|
||||
const char *pData = 0;
|
||||
|
||||
|
@ -2160,7 +2160,7 @@ void CClient::ProcessServerPacketDummy(CNetChunk *pPacket)
|
|||
int GameTick = Unpacker.GetInt();
|
||||
int DeltaTick = GameTick - Unpacker.GetInt();
|
||||
int PartSize = 0;
|
||||
int Crc = 0;
|
||||
unsigned int Crc = 0;
|
||||
int CompleteSize = 0;
|
||||
const char *pData = 0;
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ void CServerBrowser::Filter()
|
|||
{
|
||||
// check for friend
|
||||
m_ppServerlist[i]->m_Info.m_FriendState = IFriends::FRIEND_NO;
|
||||
for(p = 0; p < m_ppServerlist[i]->m_Info.m_NumClients; p++)
|
||||
for(p = 0; p < minimum(m_ppServerlist[i]->m_Info.m_NumClients, (int)MAX_CLIENTS); p++)
|
||||
{
|
||||
m_ppServerlist[i]->m_Info.m_aClients[p].m_FriendState = m_pFriends->GetFriendState(m_ppServerlist[i]->m_Info.m_aClients[p].m_aName,
|
||||
m_ppServerlist[i]->m_Info.m_aClients[p].m_aClan);
|
||||
|
@ -500,6 +500,7 @@ CServerBrowser::CServerEntry *CServerBrowser::Add(const NETADDR &Addr)
|
|||
CServerEntry **ppNewlist;
|
||||
m_NumServerCapacity += 100;
|
||||
ppNewlist = (CServerEntry **)calloc(m_NumServerCapacity, sizeof(CServerEntry *));
|
||||
if(m_NumServers > 0)
|
||||
mem_copy(ppNewlist, m_ppServerlist, m_NumServers * sizeof(CServerEntry *));
|
||||
free(m_ppServerlist);
|
||||
m_ppServerlist = ppNewlist;
|
||||
|
|
|
@ -310,6 +310,7 @@ void CNetBase::SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Ack, int Con
|
|||
Construct.m_NumChunks = 0;
|
||||
Construct.m_DataSize = 1 + ExtraSize;
|
||||
Construct.m_aChunkData[0] = ControlMsg;
|
||||
if(pExtra)
|
||||
mem_copy(&Construct.m_aChunkData[1], pExtra, ExtraSize);
|
||||
|
||||
// send the control message
|
||||
|
|
|
@ -59,9 +59,9 @@ int CSnapshot::GetItemIndex(int Key)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int CSnapshot::Crc()
|
||||
unsigned CSnapshot::Crc()
|
||||
{
|
||||
int Crc = 0;
|
||||
unsigned int Crc = 0;
|
||||
|
||||
for(int i = 0; i < m_NumItems; i++)
|
||||
{
|
||||
|
@ -230,7 +230,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
}
|
||||
|
||||
GenerateHash(Hashlist, pFrom);
|
||||
int aPastIndecies[1024];
|
||||
int aPastIndices[1024];
|
||||
|
||||
// fetch previous indices
|
||||
// we do this as a separate pass because it helps the cache
|
||||
|
@ -238,7 +238,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
for(i = 0; i < NumItems; i++)
|
||||
{
|
||||
pCurItem = pTo->GetItem(i); // O(1) .. O(n)
|
||||
aPastIndecies[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n)
|
||||
aPastIndices[i] = GetItemIndexHashed(pCurItem->Key(), Hashlist); // O(n) .. O(n^n)
|
||||
}
|
||||
|
||||
for(i = 0; i < NumItems; i++)
|
||||
|
@ -246,7 +246,7 @@ int CSnapshotDelta::CreateDelta(CSnapshot *pFrom, CSnapshot *pTo, void *pDstData
|
|||
// do delta
|
||||
ItemSize = pTo->GetItemSize(i); // O(1) .. O(n)
|
||||
pCurItem = pTo->GetItem(i); // O(1) .. O(n)
|
||||
PastIndex = aPastIndecies[i];
|
||||
PastIndex = aPastIndices[i];
|
||||
|
||||
if(PastIndex != -1)
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
int GetItemIndex(int Key);
|
||||
int GetItemType(int Index);
|
||||
|
||||
int Crc();
|
||||
unsigned Crc();
|
||||
void DebugDump();
|
||||
static void RemoveExtraInfo(unsigned char *pData);
|
||||
};
|
||||
|
|
|
@ -597,7 +597,7 @@ void CGhost::OnMessage(int MsgType, void *pRawMsg)
|
|||
{
|
||||
char aName[MAX_NAME_LENGTH];
|
||||
int Time = CRaceHelper::TimeFromFinishMessage(pMsg->m_pMessage, aName, sizeof(aName));
|
||||
if(Time > 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) == 0)
|
||||
if(Time > 0 && m_pClient->m_Snap.m_LocalClientID >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) == 0)
|
||||
{
|
||||
StopRecord(Time);
|
||||
StopRender();
|
||||
|
|
|
@ -105,8 +105,13 @@ void CMenus::RenderGame(CUIRect MainView)
|
|||
static int s_JoinRedButton = 0;
|
||||
static int s_JoinBlueButton = 0;
|
||||
|
||||
bool Paused = m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_Paused;
|
||||
bool Spec = m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_Spec;
|
||||
bool Paused = false;
|
||||
bool Spec = false;
|
||||
if(m_pClient->m_Snap.m_LocalClientID >= 0)
|
||||
{
|
||||
Paused = m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_Paused;
|
||||
Spec = m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_Spec;
|
||||
}
|
||||
|
||||
if(m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pGameInfoObj && !Paused && !Spec)
|
||||
{
|
||||
|
|
|
@ -194,7 +194,7 @@ void CPlayers::RenderPlayer(
|
|||
bool PredictLocalWeapons = false;
|
||||
float AttackTime = (Client()->PrevGameTick(g_Config.m_ClDummy) - Player.m_AttackTick) / (float)SERVER_TICK_SPEED + Client()->GameTickTime(g_Config.m_ClDummy);
|
||||
float LastAttackTime = (Client()->PrevGameTick(g_Config.m_ClDummy) - Player.m_AttackTick) / (float)SERVER_TICK_SPEED + s_LastGameTickTime;
|
||||
if(m_pClient->m_aClients[ClientID].m_IsPredictedLocal && m_pClient->AntiPingGunfire())
|
||||
if(ClientID >= 0 && m_pClient->m_aClients[ClientID].m_IsPredictedLocal && m_pClient->AntiPingGunfire())
|
||||
{
|
||||
PredictLocalWeapons = true;
|
||||
AttackTime = (Client()->PredIntraGameTick(g_Config.m_ClDummy) + (Client()->PredGameTick(g_Config.m_ClDummy) - 1 - Player.m_AttackTick)) / (float)SERVER_TICK_SPEED;
|
||||
|
|
|
@ -131,7 +131,7 @@ void CRaceDemo::OnMessage(int MsgType, void *pRawMsg)
|
|||
{
|
||||
char aName[MAX_NAME_LENGTH];
|
||||
int Time = CRaceHelper::TimeFromFinishMessage(pMsg->m_pMessage, aName, sizeof(aName));
|
||||
if(Time > 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) == 0)
|
||||
if(Time > 0 && m_pClient->m_Snap.m_LocalClientID >= 0 && str_comp(aName, m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID].m_aName) == 0)
|
||||
{
|
||||
m_RaceState = RACE_FINISHED;
|
||||
m_RecordStopTick = Client()->GameTick(g_Config.m_ClDummy) + Client()->GameTickSpeed();
|
||||
|
|
|
@ -138,8 +138,12 @@ int CSkins::LoadSkin(const char *pName, const char *pPath, int DirType, int *pGe
|
|||
for(int x = 0; x < BodySize; x++)
|
||||
{
|
||||
int v = d[y * Pitch + x * 4];
|
||||
if(v <= OrgWeight)
|
||||
if(OrgWeight == 0)
|
||||
v = 0;
|
||||
else if(v <= OrgWeight)
|
||||
v = (int)(((v / (float)OrgWeight) * NewWeight));
|
||||
else if(InvOrgWeight == 0)
|
||||
v = NewWeight;
|
||||
else
|
||||
v = (int)(((v - OrgWeight) / (float)InvOrgWeight) * InvNewWeight + NewWeight);
|
||||
d[y * Pitch + x * 4] = v;
|
||||
|
|
|
@ -64,10 +64,7 @@ void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore
|
|||
|
||||
m_pTeams = pTeams;
|
||||
m_Id = -1;
|
||||
m_Hook = true;
|
||||
m_Collision = true;
|
||||
m_JumpedTotal = 0;
|
||||
m_Jumps = 2;
|
||||
Reset();
|
||||
}
|
||||
|
||||
void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams, std::map<int, std::vector<vec2>> *pTeleOuts)
|
||||
|
@ -78,10 +75,7 @@ void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore
|
|||
|
||||
m_pTeams = pTeams;
|
||||
m_Id = -1;
|
||||
m_Hook = true;
|
||||
m_Collision = true;
|
||||
m_JumpedTotal = 0;
|
||||
m_Jumps = 2;
|
||||
Reset();
|
||||
}
|
||||
|
||||
void CCharacterCore::Reset()
|
||||
|
@ -274,7 +268,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
{
|
||||
CCharacterCore *pCharCore = m_pWorld->m_apCharacters[i];
|
||||
if(!pCharCore || pCharCore == this || (!(m_Super || pCharCore->m_Super) && (!m_pTeams->CanCollide(i, m_Id) || pCharCore->m_Solo || m_Solo)))
|
||||
if(!pCharCore || pCharCore == this || (!(m_Super || pCharCore->m_Super) && ((m_Id != -1 && !m_pTeams->CanCollide(i, m_Id)) || pCharCore->m_Solo || m_Solo)))
|
||||
continue;
|
||||
|
||||
vec2 ClosestPoint = closest_point_on_line(m_HookPos, NewPos, pCharCore->m_Pos);
|
||||
|
@ -328,7 +322,7 @@ void CCharacterCore::Tick(bool UseInput)
|
|||
if(m_HookedPlayer != -1)
|
||||
{
|
||||
CCharacterCore *pCharCore = m_pWorld->m_apCharacters[m_HookedPlayer];
|
||||
if(pCharCore && m_pTeams->CanKeepHook(m_Id, pCharCore->m_Id))
|
||||
if(pCharCore && m_Id != -1 && m_pTeams->CanKeepHook(m_Id, pCharCore->m_Id))
|
||||
m_HookPos = pCharCore->m_Pos;
|
||||
else
|
||||
{
|
||||
|
@ -581,7 +575,7 @@ bool CCharacterCore::IsSwitchActiveCb(int Number, void *pUser)
|
|||
{
|
||||
CCharacterCore *pThis = (CCharacterCore *)pUser;
|
||||
if(pThis->Collision()->m_pSwitchers)
|
||||
if(pThis->m_pTeams->Team(pThis->m_Id) != (pThis->m_pTeams->m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER))
|
||||
if(pThis->m_Id != -1 && pThis->m_pTeams->Team(pThis->m_Id) != (pThis->m_pTeams->m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER))
|
||||
return pThis->Collision()->m_pSwitchers[Number].m_Status[pThis->m_pTeams->Team(pThis->m_Id)];
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue