From 57f6bf6eeafd22f19151391a1c4cba1643135b84 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 7 Oct 2023 05:04:46 +0300 Subject: [PATCH] fix some undefined/unspecified behaviours in multiplayer games( may help with #299 ) --- engine/NetworkStringTableItem.cpp | 2 +- engine/downloadthread.cpp | 2 +- engine/pure_server.cpp | 2 +- engine/sv_main.cpp | 2 +- engine/vengineserver_impl.cpp | 2 +- game/client/game_controls/teammenu.cpp | 13 +++++++------ public/mathlib/ssemath.h | 6 +++--- public/soundflags.h | 2 +- togl/linuxwin/dx9asmtogl2.cpp | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/engine/NetworkStringTableItem.cpp b/engine/NetworkStringTableItem.cpp index a17db72e..5a066220 100644 --- a/engine/NetworkStringTableItem.cpp +++ b/engine/NetworkStringTableItem.cpp @@ -199,7 +199,7 @@ bool CNetworkStringTableItem::SetUserData( int tick, int length, const void *use if ( length > 0 ) { - m_pUserData = new unsigned char[ length ]; + m_pUserData = new unsigned char[ALIGN_VALUE( length, 4 )]; Q_memcpy( m_pUserData, userData, length ); } else diff --git a/engine/downloadthread.cpp b/engine/downloadthread.cpp index 882609f7..be1974cf 100644 --- a/engine/downloadthread.cpp +++ b/engine/downloadthread.cpp @@ -921,7 +921,7 @@ void DownloadThread( void *voidPtr ) // Delete rc.data, which was allocated in this thread if ( rc.data != NULL ) { - delete[] rc.data; + free(rc.data); rc.data = NULL; } diff --git a/engine/pure_server.cpp b/engine/pure_server.cpp index b3b39f74..b233e93a 100644 --- a/engine/pure_server.cpp +++ b/engine/pure_server.cpp @@ -226,7 +226,7 @@ bool CPureServerWhitelist::LoadCommandsFromKeyValues( KeyValues *kv ) else Warning( "Unknown modifier in whitelist file: %s.\n", mods[i] ); } - mods.PurgeAndDeleteElements(); + mods.PurgeAndDeleteElementsArray(); if ( ( bFromTrustedSource && ( bAllowFromDisk || bCheckCRC || bAny ) ) || ( bAny && bCheckCRC ) ) diff --git a/engine/sv_main.cpp b/engine/sv_main.cpp index 80c1cc4d..4d07f442 100644 --- a/engine/sv_main.cpp +++ b/engine/sv_main.cpp @@ -1227,7 +1227,7 @@ void SV_DetermineMulticastRecipients( bool usepas, const Vector& origin, CBitVec serverGameClients->ClientEarPosition( pClient->edict, &vecEarPosition ); int iBitNumber = CM_LeafCluster( CM_PointLeafnum( vecEarPosition ) ); - if ( !(pMask[iBitNumber>>3] & (1<<(iBitNumber&7)) ) ) + if ( iBitNumber < 0 || !(pMask[iBitNumber>>3] & (1<<(iBitNumber&7)) ) ) continue; playerbits.Set( i ); diff --git a/engine/vengineserver_impl.cpp b/engine/vengineserver_impl.cpp index 37dc07c6..b28cb5a7 100644 --- a/engine/vengineserver_impl.cpp +++ b/engine/vengineserver_impl.cpp @@ -1842,7 +1842,7 @@ void CVEngineServer::PlaybackTempEntity( IRecipientFilter& filter, float delay, newEvent->bits = buffer.GetNumBitsWritten(); int size = Bits2Bytes( buffer.GetNumBitsWritten() ); - newEvent->pData = new byte[size]; + newEvent->pData = new byte[ALIGN_VALUE(size,4)]; Q_memcpy( newEvent->pData, data, size ); // add to list diff --git a/game/client/game_controls/teammenu.cpp b/game/client/game_controls/teammenu.cpp index e1adf32d..7a6a1167 100644 --- a/game/client/game_controls/teammenu.cpp +++ b/game/client/game_controls/teammenu.cpp @@ -115,7 +115,7 @@ void CTeamMenu::ApplySchemeSettings(IScheme *pScheme) if ( *m_szMapName ) { - LoadMapPage( m_szMapName ); // reload the map description to pick up the color + LoadMapPage( NULL ); // reload the map description to pick up the color } } @@ -185,22 +185,23 @@ void CTeamMenu::Update() void CTeamMenu::LoadMapPage( const char *mapName ) { // Save off the map name so we can re-load the page in ApplySchemeSettings(). - Q_strncpy( m_szMapName, mapName, strlen( mapName ) + 1 ); - + if( mapName ) + Q_strncpy( m_szMapName, mapName, strlen( mapName ) + 1 ); + char mapRES[ MAX_PATH ]; char uilanguage[ 64 ]; uilanguage[0] = 0; engine->GetUILanguage( uilanguage, sizeof( uilanguage ) ); - Q_snprintf( mapRES, sizeof( mapRES ), "resource/maphtml/%s_%s.html", mapName, uilanguage ); + Q_snprintf( mapRES, sizeof( mapRES ), "resource/maphtml/%s_%s.html", m_szMapName, uilanguage ); bool bFoundHTML = false; if ( !g_pFullFileSystem->FileExists( mapRES ) ) { // try english - Q_snprintf( mapRES, sizeof( mapRES ), "resource/maphtml/%s_english.html", mapName ); + Q_snprintf( mapRES, sizeof( mapRES ), "resource/maphtml/%s_english.html", m_szMapName ); } else { @@ -240,7 +241,7 @@ void CTeamMenu::LoadMapPage( const char *mapName ) #endif } - Q_snprintf( mapRES, sizeof( mapRES ), "maps/%s.txt", mapName); + Q_snprintf( mapRES, sizeof( mapRES ), "maps/%s.txt", m_szMapName); // if no map specific description exists, load default text if( !g_pFullFileSystem->FileExists( mapRES ) ) diff --git a/public/mathlib/ssemath.h b/public/mathlib/ssemath.h index 8b9def86..54141995 100644 --- a/public/mathlib/ssemath.h +++ b/public/mathlib/ssemath.h @@ -1787,14 +1787,14 @@ FORCEINLINE fltx4 LoadAlignedSIMD( const VectorAligned & pSIMD ) return SetWToZeroSIMD( LoadAlignedSIMD(pSIMD.Base()) ); } -#ifdef __SANITIZE_ADDRESS__ -static __attribute__((no_sanitize("address"))) fltx4 LoadUnalignedSIMD( const void *pSIMD ) +#ifdef USING_ASAN +static NO_ASAN fltx4 LoadUnalignedSIMD( const void *pSIMD ) { return _mm_loadu_ps( reinterpret_cast( pSIMD ) ); } -static __attribute__((no_sanitize("address"))) fltx4 LoadUnaligned3SIMD( const void *pSIMD ) +static NO_ASAN fltx4 LoadUnaligned3SIMD( const void *pSIMD ) { return _mm_loadu_ps( reinterpret_cast( pSIMD ) ); } diff --git a/public/soundflags.h b/public/soundflags.h index 71ae1192..7739a156 100644 --- a/public/soundflags.h +++ b/public/soundflags.h @@ -50,7 +50,7 @@ enum // Don't change this without consulting Kelly or Wedge (sjb). #define ATTN_GUNFIRE 0.27f -enum soundlevel_t +enum soundlevel_t : int { SNDLVL_NONE = 0, diff --git a/togl/linuxwin/dx9asmtogl2.cpp b/togl/linuxwin/dx9asmtogl2.cpp index 281df0b4..270f1a16 100644 --- a/togl/linuxwin/dx9asmtogl2.cpp +++ b/togl/linuxwin/dx9asmtogl2.cpp @@ -1010,7 +1010,7 @@ CUtlString D3DToGL::FixGLSLSwizzle( const char *pDestRegisterName, const char *p { bool bAbsWrapper = false; // Parameter wrapped in an abs() bool bAbsNegative = false; // -abs() - char szSrcRegister[128]; + static char szSrcRegister[128]; V_strncpy( szSrcRegister, pSrcRegisterName, sizeof(szSrcRegister) ); // Check for abs() or -abs() wrapper and strip it off during the fixup