From 29db778997a4db7ddc1b18b9762f17d113f37329 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Tue, 14 Jun 2022 13:16:08 +0300 Subject: [PATCH] fix some AddressSanitizer issues --- engine/cmd.cpp | 2 +- game/client/hud_closecaption.cpp | 5 +++-- game/client/particlemgr.cpp | 2 +- game/server/ai_behavior_follow.cpp | 17 ++++++++--------- game/server/ai_behavior_follow.h | 2 +- game/server/hl2/npc_antlion.cpp | 4 ++-- game/shared/props_shared.cpp | 10 +++++----- game/shared/props_shared.h | 10 +++++----- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/engine/cmd.cpp b/engine/cmd.cpp index 689832b1..b9567271 100644 --- a/engine/cmd.cpp +++ b/engine/cmd.cpp @@ -624,7 +624,7 @@ void Cmd_Exec_f( const CCommand &args ) } } - char buf[16384] = { 0 }; + static char buf[16384] = { 0 }; int len = 0; char *f = (char *)COM_LoadStackFile( fileName, buf, sizeof( buf ), len ); if ( !f ) diff --git a/game/client/hud_closecaption.cpp b/game/client/hud_closecaption.cpp index f72b9fc1..0e25341b 100644 --- a/game/client/hud_closecaption.cpp +++ b/game/client/hud_closecaption.cpp @@ -543,7 +543,7 @@ struct AsyncCaptionData_t data->m_nBlockNum = params.blocktoload; data->m_nFileIndex = params.fileindex; data->m_nBlockSize = params.blocksize; - data->m_pBlockData = new byte[ data->m_nBlockSize ]; + data->m_pBlockData = new byte[ data->m_nBlockSize * sizeof(ucs2) ]; return data; } @@ -2027,6 +2027,7 @@ public: if ( entry.blockNum != nBlockNum ) continue; + #ifdef WIN32 const wchar_t *pIn = ( const wchar_t *)&pData->m_pBlockData[ entry.offset ]; caption->stream = new wchar_t[ entry.length >> 1 ]; @@ -2034,7 +2035,7 @@ public: #else // we persist to disk as ucs2 so convert back to real unicode here caption->stream = new wchar_t[ entry.length ]; - V_UCS2ToUnicode( (ucs2 *)&pData->m_pBlockData[ entry.offset ], caption->stream, entry.length*sizeof(wchar_t) ); + V_UCS2ToUnicode( (ucs2 *)&pData->m_pBlockData[ entry.offset ], caption->stream, entry.length << 1 ); #endif } } diff --git a/game/client/particlemgr.cpp b/game/client/particlemgr.cpp index d62c6e73..792711ed 100644 --- a/game/client/particlemgr.cpp +++ b/game/client/particlemgr.cpp @@ -1014,7 +1014,7 @@ bool CParticleEffectBinding::RecalculateBoundingBox() CEffectMaterial* CParticleEffectBinding::GetEffectMaterial( CParticleSubTexture *pSubTexture ) { // Hash the IMaterial pointer. - unsigned long index = (((unsigned long)pSubTexture->m_pGroup) >> 6) % EFFECT_MATERIAL_HASH_SIZE; + unsigned int index = (((unsigned int)pSubTexture->m_pGroup) >> 6) % EFFECT_MATERIAL_HASH_SIZE; for ( CEffectMaterial *pCur=m_EffectMaterialHash[index]; pCur; pCur = pCur->m_pHashedNext ) { if ( pCur->m_pGroup == pSubTexture->m_pGroup ) diff --git a/game/server/ai_behavior_follow.cpp b/game/server/ai_behavior_follow.cpp index 4c77972c..40f66583 100644 --- a/game/server/ai_behavior_follow.cpp +++ b/game/server/ai_behavior_follow.cpp @@ -53,7 +53,7 @@ struct AI_Follower_t } AIHANDLE hFollower; - int slot; + intp slot; AI_FollowNavInfo_t navInfo; AI_FollowGroup_t * pGroup; // backpointer for efficiency }; @@ -2561,7 +2561,7 @@ bool CAI_FollowManager::AddFollower( CBaseEntity *pTarget, CAI_BaseNPC *pFollowe AI_FollowSlot_t *pSlot = &pGroup->pFormation->pSlots[slot]; - int i = pGroup->followers.AddToTail( ); + intp i = pGroup->followers.AddToTail( ); AI_Follower_t *iterNode = &pGroup->followers[i]; iterNode->hFollower = pFollower; @@ -2569,9 +2569,8 @@ bool CAI_FollowManager::AddFollower( CBaseEntity *pTarget, CAI_BaseNPC *pFollowe iterNode->pGroup = pGroup; pGroup->slotUsage.Set( slot ); - CalculateFieldsFromSlot( pSlot, &iterNode->navInfo ); - + pHandle->m_hFollower = i; pHandle->m_pGroup = pGroup; return true; @@ -2641,10 +2640,10 @@ bool CAI_FollowManager::RedistributeSlots( AI_FollowGroup_t *pGroup ) { AI_FollowSlot_t * pSlot = &pGroup->pFormation->pSlots[bestSlot]; Vector slotPos = originFollowed + pSlot->position; - int h = pGroup->followers.Head(); - int hBest = pGroup->followers.InvalidIndex(); + intp h = pGroup->followers.Head(); + intp hBest = pGroup->followers.InvalidIndex(); float distSqBest = FLT_MAX; - + while ( h != pGroup->followers.InvalidIndex() ) { AI_Follower_t *p = &pGroup->followers[h]; @@ -2691,7 +2690,7 @@ void CAI_FollowManager::ChangeFormation( AI_FollowManagerInfoHandle_t& hInfo, AI if ( pNewFormation == pGroup->pFormation ) return; - int h = pGroup->followers.Head(); + intp h = pGroup->followers.Head(); while ( h != pGroup->followers.InvalidIndex() ) { @@ -2738,7 +2737,7 @@ void CAI_FollowManager::RemoveFollower( AI_FollowManagerInfoHandle_t& hInfo ) AI_FollowGroup_t *pGroup = hInfo.m_pGroup; AI_Follower_t* iterNode = &pGroup->followers[hInfo.m_hFollower]; - int slot = iterNode->slot; + intp slot = iterNode->slot; pGroup->slotUsage.Clear( slot ); pGroup->followers.Remove( hInfo.m_hFollower ); if ( pGroup->followers.Count() == 0 ) diff --git a/game/server/ai_behavior_follow.h b/game/server/ai_behavior_follow.h index a0e43837..ad734f53 100644 --- a/game/server/ai_behavior_follow.h +++ b/game/server/ai_behavior_follow.h @@ -100,7 +100,7 @@ struct AI_FollowGroup_t; struct AI_FollowManagerInfoHandle_t { AI_FollowGroup_t *m_pGroup; - int m_hFollower; + intp m_hFollower; }; //------------------------------------- diff --git a/game/server/hl2/npc_antlion.cpp b/game/server/hl2/npc_antlion.cpp index 8cb7f789..eaaaa31d 100644 --- a/game/server/hl2/npc_antlion.cpp +++ b/game/server/hl2/npc_antlion.cpp @@ -4015,8 +4015,8 @@ bool CNPC_Antlion::CorpseGib( const CTakeDamageInfo &info ) } Vector velocity = vec3_origin; - AngularImpulse angVelocity = RandomAngularImpulse( -150, 150 ); - breakablepropparams_t params( EyePosition(), GetAbsAngles(), velocity, angVelocity ); + AngularImpulse angVelocity = RandomAngularImpulse( -150, 150 ); + static breakablepropparams_t params( EyePosition(), GetAbsAngles(), velocity, angVelocity ); params.impactEnergyScale = 1.0f; params.defBurstScale = 150.0f; params.defCollisionGroup = COLLISION_GROUP_DEBRIS; diff --git a/game/shared/props_shared.cpp b/game/shared/props_shared.cpp index 6d0f9209..80ab39b7 100644 --- a/game/shared/props_shared.cpp +++ b/game/shared/props_shared.cpp @@ -951,7 +951,7 @@ void PropBreakableCreateAll( int modelindex, IPhysicsObject *pPhysics, const bre nSkin = pOwnerAnim->m_nSkin; } } - matrix3x4_t localToWorld; + static matrix3x4_t localToWorld; CStudioHdr studioHdr; const model_t *model = modelinfo->GetModel( modelindex ); @@ -1009,7 +1009,7 @@ void PropBreakableCreateAll( int modelindex, IPhysicsObject *pPhysics, const bre if ( ( iPrecomputedBreakableCount != -1 ) && ( i >= iPrecomputedBreakableCount ) ) break; - matrix3x4_t matrix; + static matrix3x4_t matrix; AngleMatrix( params.angles, params.origin, matrix ); CStudioHdr studioHdr; @@ -1188,7 +1188,7 @@ void PropBreakableCreateAll( int modelindex, IPhysicsObject *pPhysics, const bre Vector vecBreakableObbSize = pBreakable->CollisionProp()->OBBSize(); // Try to align the gibs along the original axis - matrix3x4_t matrix; + static matrix3x4_t matrix; AngleMatrix( vecAngles, matrix ); AlignBoxes( &matrix, vecObbSize, vecBreakableObbSize ); MatrixAngles( matrix, vecAngles ); @@ -1397,7 +1397,7 @@ CBaseEntity *CreateGibsFromList( CUtlVector &list, int modelindex, if ( ( iPrecomputedBreakableCount != -1 ) && ( i >= iPrecomputedBreakableCount ) ) break; - matrix3x4_t matrix; + static matrix3x4_t matrix; AngleMatrix( params.angles, params.origin, matrix ); CStudioHdr studioHdr; @@ -1596,7 +1596,7 @@ CBaseEntity *CreateGibsFromList( CUtlVector &list, int modelindex, Vector vecBreakableObbSize = pBreakable->CollisionProp()->OBBSize(); // Try to align the gibs along the original axis - matrix3x4_t matrix; + static matrix3x4_t matrix; AngleMatrix( vecAngles, matrix ); AlignBoxes( &matrix, vecObbSize, vecBreakableObbSize ); MatrixAngles( matrix, vecAngles ); diff --git a/game/shared/props_shared.h b/game/shared/props_shared.h index c63cb212..03dcb169 100644 --- a/game/shared/props_shared.h +++ b/game/shared/props_shared.h @@ -221,7 +221,7 @@ struct breakmodel_t struct breakablepropparams_t { - breakablepropparams_t( const Vector &_origin, const QAngle &_angles, const Vector &_velocity, const AngularImpulse &_angularVelocity ) + breakablepropparams_t( const Vector _origin, const QAngle _angles, const Vector _velocity, const AngularImpulse _angularVelocity ) : origin(_origin), angles(_angles), velocity(_velocity), angularVelocity(_angularVelocity) { impactEnergyScale = 0; @@ -230,10 +230,10 @@ struct breakablepropparams_t nDefaultSkin = 0; } - const Vector &origin; - const QAngle &angles; - const Vector &velocity; - const AngularImpulse &angularVelocity; + const Vector origin; + const QAngle angles; + const Vector velocity; + const AngularImpulse angularVelocity; float impactEnergyScale; float defBurstScale; int defCollisionGroup;