6032: Fix some strict-aliasing warnings and too large snapshot buffers r=heinrich5991 a=Robyt3



## Checklist

- [X] 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:
bors[bot] 2022-11-12 20:04:02 +00:00 committed by GitHub
commit 3c5e2ad210
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 21 deletions

View file

@ -3850,22 +3850,17 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
GameClient()->OnConnected();
// setup buffers
mem_zero(m_aaapDemorecSnapshotData, sizeof(m_aaapDemorecSnapshotData));
mem_zero(m_aaaDemorecSnapshotData, sizeof(m_aaaDemorecSnapshotData));
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT] = &m_aDemorecSnapshotHolders[SNAP_CURRENT];
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV] = &m_aDemorecSnapshotHolders[SNAP_PREV];
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_pSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_CURRENT][0];
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_pAltSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_CURRENT][1];
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_SnapSize = 0;
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_AltSnapSize = 0;
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_Tick = -1;
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_pSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_PREV][0];
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_pAltSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_PREV][1];
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_SnapSize = 0;
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_AltSnapSize = 0;
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_Tick = -1;
for(int SnapshotType = 0; SnapshotType < NUM_SNAPSHOT_TYPES; SnapshotType++)
{
m_aapSnapshots[g_Config.m_ClDummy][SnapshotType] = &m_aDemorecSnapshotHolders[SnapshotType];
m_aapSnapshots[g_Config.m_ClDummy][SnapshotType]->m_pSnap = (CSnapshot *)&m_aaaDemorecSnapshotData[SnapshotType][0];
m_aapSnapshots[g_Config.m_ClDummy][SnapshotType]->m_pAltSnap = (CSnapshot *)&m_aaaDemorecSnapshotData[SnapshotType][1];
m_aapSnapshots[g_Config.m_ClDummy][SnapshotType]->m_SnapSize = 0;
m_aapSnapshots[g_Config.m_ClDummy][SnapshotType]->m_AltSnapSize = 0;
m_aapSnapshots[g_Config.m_ClDummy][SnapshotType]->m_Tick = -1;
}
// enter demo playback state
SetState(IClient::STATE_DEMOPLAYBACK);

View file

@ -240,7 +240,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
int m_aSnapshotIncomingDataSize[NUM_DUMMIES];
CSnapshotStorage::CHolder m_aDemorecSnapshotHolders[NUM_SNAPSHOT_TYPES];
char *m_aaapDemorecSnapshotData[NUM_SNAPSHOT_TYPES][2][CSnapshot::MAX_SIZE];
char m_aaaDemorecSnapshotData[NUM_SNAPSHOT_TYPES][2][CSnapshot::MAX_SIZE];
CSnapshotDelta m_SnapshotDelta;

View file

@ -3594,15 +3594,15 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
{
int TypeID;
int ItemID;
int *pData = (int *)Reader.GetItem(i, &TypeID, &ItemID);
void *pData = Reader.GetItem(i, &TypeID, &ItemID);
int Size = Reader.GetItemSize(i);
CMapItemInfoSettings MapInfo;
if(TypeID == MAPITEMTYPE_INFO && ItemID == 0)
{
FoundInfo = true;
CMapItemInfoSettings *pInfo = (CMapItemInfoSettings *)pData;
if(Size >= (int)sizeof(CMapItemInfoSettings))
{
CMapItemInfoSettings *pInfo = (CMapItemInfoSettings *)pData;
if(pInfo->m_Settings > -1)
{
SettingsIndex = pInfo->m_Settings;
@ -3620,15 +3620,15 @@ void CGameContext::OnMapChange(char *pNewMapName, int MapNameSize)
{
MapInfo = *pInfo;
MapInfo.m_Settings = SettingsIndex;
pData = (int *)&MapInfo;
pData = &MapInfo;
Size = sizeof(MapInfo);
}
}
else
{
*(CMapItemInfo *)&MapInfo = *(CMapItemInfo *)pInfo;
*(CMapItemInfo *)&MapInfo = *(CMapItemInfo *)pData;
MapInfo.m_Settings = SettingsIndex;
pData = (int *)&MapInfo;
pData = &MapInfo;
Size = sizeof(MapInfo);
}
}