mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fix aliasing warnings in CClient::DemoPlayer_Play
Fix warnings with `-fstrict-aliasing` and `-Wstrict-aliasing=2` by using char array instead of array of char pointers: ``` src/engine/client/client.cpp: In member function 'virtual const char* CClient::DemoPlayer_Play(const char*, int)': src/engine/client/client.cpp:3858:123: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 3858 | m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_pSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_CURRENT][0]; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ src/engine/client/client.cpp:3859:126: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 3859 | m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_pAltSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_CURRENT][1]; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ src/engine/client/client.cpp:3864:117: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 3864 | m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_pSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_PREV][0]; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ src/engine/client/client.cpp:3865:120: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 3865 | m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_pAltSnap = (CSnapshot *)m_aaapDemorecSnapshotData[SNAP_PREV][1]; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ ``` Snapshot data during demo playback was being stored in an array of `char *` instead of an array of `char`, which caused above aliasing warnings and used 8 times more memory for the snapshot storage than being necessary.
This commit is contained in:
parent
ea06a13429
commit
c988a71d3e
|
@ -3850,19 +3850,19 @@ 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_pSnap = (CSnapshot *)&m_aaaDemorecSnapshotData[SNAP_CURRENT][0];
|
||||
m_aapSnapshots[g_Config.m_ClDummy][SNAP_CURRENT]->m_pAltSnap = (CSnapshot *)&m_aaaDemorecSnapshotData[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_pSnap = (CSnapshot *)&m_aaaDemorecSnapshotData[SNAP_PREV][0];
|
||||
m_aapSnapshots[g_Config.m_ClDummy][SNAP_PREV]->m_pAltSnap = (CSnapshot *)&m_aaaDemorecSnapshotData[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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue