fix address sanitizer issues

This commit is contained in:
nillerusr 2022-04-25 17:21:00 +03:00
parent a5e9cdcbe2
commit 2ec2a47a53
17 changed files with 43 additions and 37 deletions

View File

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

View File

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

View File

@ -52,7 +52,7 @@ public:
{
if ( pData )
{
delete pData;
delete[] pData;
}
}
@ -65,7 +65,7 @@ public:
pSendTable = src.pSendTable;
pClientClass = src.pClientClass;
filter.AddPlayersFromFilter( &src.filter );
if ( src.pData )
{
int size = Bits2Bytes( src.bits );

View File

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

View File

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

View File

@ -2048,34 +2048,34 @@ public:
class CClipPlane
{
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;
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 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;
}
private:
static const Vector *m_pNormal;
static const Vector m_pNormal;
static float m_Dist;
};
const Vector *CClipPlane::m_pNormal;
const Vector CClipPlane::m_pNormal;
float CClipPlane::m_Dist;
static inline void ClampTexCoord( ShadowVertex_t *pInVertex, ShadowVertex_t *pOutVertex )

View File

@ -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[2] = ( clippedRay.m_Delta[2] != 0.0f ) ? 1.0f / clippedRay.m_Delta[2] : FLT_MAX;
CPartitionVisits *pPrevVisits = BeginVisit();
m_lock.LockForRead();
CPartitionVisits *pPrevVisits = BeginVisit();
if ( ray.m_IsRay )
{
EnumerateElementsAlongRay_Ray( listMask, clippedRay, vecInvDelta, vecEnd, pIterator );

View File

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

View File

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

View File

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

View File

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

View File

@ -45,9 +45,8 @@ public:
DECLARE_DATADESC();
private:
bool UpdateState( void );
int m_state;
bool UpdateState( void );
int m_state;
};
LINK_ENTITY_TO_CLASS( func_areaportal, CAreaPortal );

View File

@ -71,20 +71,18 @@ void CreateDumpDirectory( const char *szDirectoryName )
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
{
void *pMemory = new unsigned char [ sizeof( CPolyhedron_AllocByNew ) +
void *pMemory = malloc(sizeof( CPolyhedron_AllocByNew ) +
(iVertices * sizeof(Vector)) +
(iLines * sizeof(Polyhedron_IndexedLine_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;
#include "tier0/memdbgon.h"
pAllocated->iVertexCount = iVertices;
pAllocated->iLineCount = iLines;
@ -106,7 +104,7 @@ public:
int iReferenceCount;
#endif
virtual void Release( void )
void Release( void ) override
{
#ifdef DBGFLAG_ASSERT
--iReferenceCount;

View File

@ -42,7 +42,7 @@ public:
Polyhedron_IndexedLine_t *pLines;
Polyhedron_IndexedLineReference_t *pIndices;
Polyhedron_IndexedPolygon_t *pPolygons;
unsigned short iVertexCount;
unsigned short iLineCount;
unsigned short iIndexCount;
@ -53,10 +53,10 @@ public:
Vector Center( void );
};
class CPolyhedron_AllocByNew : public CPolyhedron
class CPolyhedron_AllocByNew final : public CPolyhedron
{
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
private:

View File

@ -2062,6 +2062,8 @@ struct studiohdr2_t
struct studiohdr_t
{
DECLARE_BYTESWAP_DATADESC();
studiohdr_t() = default;
int id;
int version;
@ -2077,10 +2079,10 @@ struct studiohdr_t
Vector illumposition; // illumination center
Vector hull_min; // ideal movement hull size
Vector hull_max;
Vector hull_max;
Vector view_bbmin; // clipping bounding box
Vector view_bbmax;
Vector view_bbmax;
int flags;
@ -2329,9 +2331,6 @@ struct studiohdr_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.
int unused2[1];
studiohdr_t() {}
private:
// No copy constructors allowed
studiohdr_t(const studiohdr_t& vOther);

View File

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

View File

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