Browse Source

fix address sanitizer issues

sanitize
nillerusr 2 years ago
parent
commit
2ec2a47a53
  1. 2
      engine/cl_main.cpp
  2. 3
      engine/cmodel.cpp
  3. 2
      engine/event_system.h
  4. 3
      engine/host_saverestore.cpp
  5. 2
      engine/net_ws.cpp
  6. 12
      engine/shadowmgr.cpp
  7. 4
      engine/spatialpartition.cpp
  8. 2
      filesystem/filesystem_async.cpp
  9. 3
      game/client/view_beams.cpp
  10. 2
      game/server/TemplateEntities.cpp
  11. 5
      game/server/ai_component.h
  12. 1
      game/server/func_areaportal.cpp
  13. 10
      mathlib/polyhedron.cpp
  14. 4
      public/mathlib/polyhedron.h
  15. 5
      public/studio.h
  16. 2
      studiorender/studiorendercontext.cpp
  17. 2
      vpklib/packedstore.cpp

2
engine/cl_main.cpp

@ -893,7 +893,7 @@ CON_COMMAND_F( connect, "Connect to specified server.", FCVAR_DONTRECORD )
{ {
ConMsg( "Usage: connect <server>\n" ); ConMsg( "Usage: connect <server>\n" );
} }
vecArgs.PurgeAndDeleteElements(); vecArgs.PurgeAndDeleteElementsArray();
} }
CON_COMMAND_F( redirect, "Redirect client to specified server.", FCVAR_DONTRECORD | FCVAR_SERVER_CAN_EXECUTE ) CON_COMMAND_F( redirect, "Redirect client to specified server.", FCVAR_DONTRECORD | FCVAR_SERVER_CAN_EXECUTE )

3
engine/cmodel.cpp

@ -2677,6 +2677,9 @@ int CM_BoxVisible( const Vector& mins, const Vector& maxs, const byte *visbi
int cluster = CM_LeafCluster( leafList[i] ); int cluster = CM_LeafCluster( leafList[i] );
int offset = cluster>>3; int offset = cluster>>3;
if( offset == -1 )
return true;
if ( offset > vissize ) if ( offset > vissize )
{ {
Sys_Error( "CM_BoxVisible: cluster %i, offset %i out of bounds %i\n", cluster, offset, vissize ); Sys_Error( "CM_BoxVisible: cluster %i, offset %i out of bounds %i\n", cluster, offset, vissize );

2
engine/event_system.h

@ -52,7 +52,7 @@ public:
{ {
if ( pData ) if ( pData )
{ {
delete pData; delete[] pData;
} }
} }

3
engine/host_saverestore.cpp

@ -806,7 +806,8 @@ int CSaveRestore::SaveGameSlot( const char *pSaveName, const char *pSaveComment,
m_bWaitingForSafeDangerousSave = bIsAutosaveDangerous; m_bWaitingForSafeDangerousSave = bIsAutosaveDangerous;
int iHeaderBufferSize = 64 + tokenSize + pSaveData->GetCurPos(); int iHeaderBufferSize = 64 + tokenSize + pSaveData->GetCurPos();
void *pMem = malloc(iHeaderBufferSize); void *pMem = new char[iHeaderBufferSize];
CUtlBuffer saveHeader( pMem, iHeaderBufferSize ); CUtlBuffer saveHeader( pMem, iHeaderBufferSize );
// Write the header -- THIS SHOULD NEVER CHANGE STRUCTURE, USE SAVE_HEADER FOR NEW HEADER INFORMATION // Write the header -- THIS SHOULD NEVER CHANGE STRUCTURE, USE SAVE_HEADER FOR NEW HEADER INFORMATION

2
engine/net_ws.cpp

@ -1389,7 +1389,7 @@ bool NET_GetLoopPacket ( netpacket_t * packet )
if ( loop->data != loop->defbuffer ) if ( loop->data != loop->defbuffer )
{ {
delete loop->data; delete[] loop->data;
loop->data = loop->defbuffer; loop->data = loop->defbuffer;
} }

12
engine/shadowmgr.cpp

@ -2050,32 +2050,32 @@ class CClipPlane
public: public:
static inline bool Inside( ShadowVertex_t const& vert ) static inline bool Inside( ShadowVertex_t const& vert )
{ {
return DotProduct( vert.m_Position, *m_pNormal ) < m_Dist; return DotProduct( vert.m_Position, m_pNormal ) < m_Dist;
} }
static inline float Clip( const Vector& one, const Vector& two ) static inline float Clip( const Vector& one, const Vector& two )
{ {
Vector dir; Vector dir;
VectorSubtract( two, one, dir ); VectorSubtract( two, one, dir );
return IntersectRayWithPlane( one, dir, *m_pNormal, m_Dist ); return IntersectRayWithPlane( one, dir, m_pNormal, m_Dist );
} }
static inline bool IsAbove() {return false;} static inline bool IsAbove() {return false;}
static inline bool IsPlane() {return true;} static inline bool IsPlane() {return true;}
static void SetPlane( const Vector& normal, float dist ) static void SetPlane( const Vector normal, float dist )
{ {
m_pNormal = &normal; m_pNormal = normal;
m_Dist = dist; m_Dist = dist;
} }
private: private:
static const Vector *m_pNormal; static const Vector m_pNormal;
static float m_Dist; static float m_Dist;
}; };
const Vector *CClipPlane::m_pNormal; const Vector CClipPlane::m_pNormal;
float CClipPlane::m_Dist; float CClipPlane::m_Dist;
static inline void ClampTexCoord( ShadowVertex_t *pInVertex, ShadowVertex_t *pOutVertex ) static inline void ClampTexCoord( ShadowVertex_t *pInVertex, ShadowVertex_t *pOutVertex )

4
engine/spatialpartition.cpp

@ -2297,9 +2297,9 @@ void CVoxelTree::EnumerateElementsAlongRay( SpatialPartitionListMask_t listMask,
vecInvDelta[1] = ( clippedRay.m_Delta[1] != 0.0f ) ? 1.0f / clippedRay.m_Delta[1] : FLT_MAX; vecInvDelta[1] = ( clippedRay.m_Delta[1] != 0.0f ) ? 1.0f / clippedRay.m_Delta[1] : FLT_MAX;
vecInvDelta[2] = ( clippedRay.m_Delta[2] != 0.0f ) ? 1.0f / clippedRay.m_Delta[2] : FLT_MAX; vecInvDelta[2] = ( clippedRay.m_Delta[2] != 0.0f ) ? 1.0f / clippedRay.m_Delta[2] : FLT_MAX;
CPartitionVisits *pPrevVisits = BeginVisit();
m_lock.LockForRead(); m_lock.LockForRead();
CPartitionVisits *pPrevVisits = BeginVisit();
if ( ray.m_IsRay ) if ( ray.m_IsRay )
{ {
EnumerateElementsAlongRay_Ray( listMask, clippedRay, vecInvDelta, vecEnd, pIterator ); EnumerateElementsAlongRay_Ray( listMask, clippedRay, vecInvDelta, vecEnd, pIterator );

2
filesystem/filesystem_async.cpp

@ -488,7 +488,7 @@ public:
{ {
if ( m_pData && m_bFreeMemory ) if ( m_pData && m_bFreeMemory )
{ {
free( (void*) m_pData ); delete[] (char*)m_pData;
} }
} }

3
game/client/view_beams.cpp

@ -1963,7 +1963,7 @@ void CViewRenderBeams::DrawBeam( Beam_t *pbeam )
// set color // set color
float srcColor[3]; float srcColor[3];
float color[3]; float color[4];
srcColor[0] = pbeam->r; srcColor[0] = pbeam->r;
srcColor[1] = pbeam->g; srcColor[1] = pbeam->g;
@ -1984,6 +1984,7 @@ void CViewRenderBeams::DrawBeam( Beam_t *pbeam )
VectorScale( color, (1/255.0), color ); VectorScale( color, (1/255.0), color );
VectorCopy( color, srcColor ); VectorCopy( color, srcColor );
VectorScale( color, ((float)pbeam->brightness / 255.0), color ); VectorScale( color, ((float)pbeam->brightness / 255.0), color );
color[3] = 1.f;
switch( pbeam->type ) switch( pbeam->type )
{ {

2
game/server/TemplateEntities.cpp

@ -385,7 +385,7 @@ void Templates_RemoveAll(void)
free(pTemplate->pszMapData); free(pTemplate->pszMapData);
if ( pTemplate->pszFixedMapData ) if ( pTemplate->pszFixedMapData )
{ {
free(pTemplate->pszFixedMapData); delete[] pTemplate->pszFixedMapData;
} }
free(pTemplate); free(pTemplate);

5
game/server/ai_component.h

@ -137,6 +137,11 @@ public:
return pResult; return pResult;
} }
void operator delete(void *p)
{
MemAlloc_Free( p );
};
private: private:
CAI_BaseNPC *m_pOuter; CAI_BaseNPC *m_pOuter;
}; };

1
game/server/func_areaportal.cpp

@ -46,7 +46,6 @@ public:
private: private:
bool UpdateState( void ); bool UpdateState( void );
int m_state; int m_state;
}; };

10
mathlib/polyhedron.cpp

@ -71,20 +71,18 @@ void CreateDumpDirectory( const char *szDirectoryName )
void CPolyhedron_AllocByNew::Release( void ) void CPolyhedron_AllocByNew::Release( void )
{ {
delete this; free(this);
} }
CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation CPolyhedron_AllocByNew *CPolyhedron_AllocByNew::Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ) //creates the polyhedron along with enough memory to hold all it's data in a single allocation
{ {
void *pMemory = new unsigned char [ sizeof( CPolyhedron_AllocByNew ) + void *pMemory = malloc(sizeof( CPolyhedron_AllocByNew ) +
(iVertices * sizeof(Vector)) + (iVertices * sizeof(Vector)) +
(iLines * sizeof(Polyhedron_IndexedLine_t)) + (iLines * sizeof(Polyhedron_IndexedLine_t)) +
(iIndices * sizeof( Polyhedron_IndexedLineReference_t )) + (iIndices * sizeof( Polyhedron_IndexedLineReference_t )) +
(iPolygons * sizeof( Polyhedron_IndexedPolygon_t ))]; (iPolygons * sizeof( Polyhedron_IndexedPolygon_t )));
#include "tier0/memdbgoff.h" //the following placement new doesn't compile with memory debugging
CPolyhedron_AllocByNew *pAllocated = new ( pMemory ) CPolyhedron_AllocByNew; CPolyhedron_AllocByNew *pAllocated = new ( pMemory ) CPolyhedron_AllocByNew;
#include "tier0/memdbgon.h"
pAllocated->iVertexCount = iVertices; pAllocated->iVertexCount = iVertices;
pAllocated->iLineCount = iLines; pAllocated->iLineCount = iLines;
@ -106,7 +104,7 @@ public:
int iReferenceCount; int iReferenceCount;
#endif #endif
virtual void Release( void ) void Release( void ) override
{ {
#ifdef DBGFLAG_ASSERT #ifdef DBGFLAG_ASSERT
--iReferenceCount; --iReferenceCount;

4
public/mathlib/polyhedron.h

@ -53,10 +53,10 @@ public:
Vector Center( void ); Vector Center( void );
}; };
class CPolyhedron_AllocByNew : public CPolyhedron class CPolyhedron_AllocByNew final : public CPolyhedron
{ {
public: public:
virtual void Release( void ); void Release( void ) override;
static CPolyhedron_AllocByNew *Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ); //creates the polyhedron along with enough memory to hold all it's data in a single allocation static CPolyhedron_AllocByNew *Allocate( unsigned short iVertices, unsigned short iLines, unsigned short iIndices, unsigned short iPolygons ); //creates the polyhedron along with enough memory to hold all it's data in a single allocation
private: private:

5
public/studio.h

@ -2062,6 +2062,8 @@ struct studiohdr2_t
struct studiohdr_t struct studiohdr_t
{ {
DECLARE_BYTESWAP_DATADESC(); DECLARE_BYTESWAP_DATADESC();
studiohdr_t() = default;
int id; int id;
int version; int version;
@ -2329,9 +2331,6 @@ struct studiohdr_t
// [and move all fields in studiohdr2_t into studiohdr_t and kill studiohdr2_t], // [and move all fields in studiohdr2_t into studiohdr_t and kill studiohdr2_t],
// or add your stuff to studiohdr2_t. See NumSrcBoneTransforms/SrcBoneTransform for the pattern to use. // or add your stuff to studiohdr2_t. See NumSrcBoneTransforms/SrcBoneTransform for the pattern to use.
int unused2[1]; int unused2[1];
studiohdr_t() {}
private: private:
// No copy constructors allowed // No copy constructors allowed
studiohdr_t(const studiohdr_t& vOther); studiohdr_t(const studiohdr_t& vOther);

2
studiorender/studiorendercontext.cpp

@ -1317,7 +1317,7 @@ void CStudioRenderContext::R_StudioDestroyStaticMeshes( int numStudioMeshes, stu
if ( *ppStudioMeshes ) if ( *ppStudioMeshes )
{ {
delete *ppStudioMeshes; delete[] *ppStudioMeshes;
*ppStudioMeshes = 0; *ppStudioMeshes = 0;
} }
} }

2
vpklib/packedstore.cpp

@ -502,7 +502,7 @@ void SplitFileComponents( char const *pFileName, char *pDirOut, char *pBaseOut,
if ( !pDirOut[0] ) if ( !pDirOut[0] )
strcpy( pDirOut, " " ); // blank dir name strcpy( pDirOut, " " ); // blank dir name
V_strcpy( pBaseOut, V_UnqualifiedFileName( pFileName ) ); V_strncpy( pBaseOut, V_UnqualifiedFileName( pFileName ), MAX_PATH );
char *pDot = strrchr( pBaseOut, '.' ); char *pDot = strrchr( pBaseOut, '.' );
if ( pDot ) if ( pDot )
{ {

Loading…
Cancel
Save