diff --git a/engine/cl_main.cpp b/engine/cl_main.cpp index 6d0134ae..9340beea 100644 --- a/engine/cl_main.cpp +++ b/engine/cl_main.cpp @@ -893,7 +893,7 @@ CON_COMMAND_F( connect, "Connect to specified server.", FCVAR_DONTRECORD ) { ConMsg( "Usage: connect \n" ); } - vecArgs.PurgeAndDeleteElements(); + vecArgs.PurgeAndDeleteElementsArray(); } CON_COMMAND_F( redirect, "Redirect client to specified server.", FCVAR_DONTRECORD | FCVAR_SERVER_CAN_EXECUTE ) diff --git a/engine/cmodel.cpp b/engine/cmodel.cpp index e9af063d..ce1c9f2d 100644 --- a/engine/cmodel.cpp +++ b/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 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 ); diff --git a/engine/event_system.h b/engine/event_system.h index 0139cb45..7d0ba8a0 100644 --- a/engine/event_system.h +++ b/engine/event_system.h @@ -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 ); diff --git a/engine/host_saverestore.cpp b/engine/host_saverestore.cpp index 3ae1feaa..6e1afa9f 100644 --- a/engine/host_saverestore.cpp +++ b/engine/host_saverestore.cpp @@ -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 diff --git a/engine/net_ws.cpp b/engine/net_ws.cpp index 3c49ab6c..a06cbb1d 100644 --- a/engine/net_ws.cpp +++ b/engine/net_ws.cpp @@ -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; } diff --git a/engine/shadowmgr.cpp b/engine/shadowmgr.cpp index d60f953c..00177ebf 100644 --- a/engine/shadowmgr.cpp +++ b/engine/shadowmgr.cpp @@ -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 ) diff --git a/engine/spatialpartition.cpp b/engine/spatialpartition.cpp index 489dd9cd..3bcc85f3 100644 --- a/engine/spatialpartition.cpp +++ b/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[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 ); diff --git a/filesystem/filesystem_async.cpp b/filesystem/filesystem_async.cpp index 4196e090..ad9bb7dd 100644 --- a/filesystem/filesystem_async.cpp +++ b/filesystem/filesystem_async.cpp @@ -488,7 +488,7 @@ public: { if ( m_pData && m_bFreeMemory ) { - free( (void*) m_pData ); + delete[] (char*)m_pData; } } diff --git a/game/client/view_beams.cpp b/game/client/view_beams.cpp index d8881244..758a5029 100644 --- a/game/client/view_beams.cpp +++ b/game/client/view_beams.cpp @@ -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 ) { diff --git a/game/server/TemplateEntities.cpp b/game/server/TemplateEntities.cpp index a5092904..c47806ea 100644 --- a/game/server/TemplateEntities.cpp +++ b/game/server/TemplateEntities.cpp @@ -385,7 +385,7 @@ void Templates_RemoveAll(void) free(pTemplate->pszMapData); if ( pTemplate->pszFixedMapData ) { - free(pTemplate->pszFixedMapData); + delete[] pTemplate->pszFixedMapData; } free(pTemplate); diff --git a/game/server/ai_component.h b/game/server/ai_component.h index 2385d61b..7722f66a 100644 --- a/game/server/ai_component.h +++ b/game/server/ai_component.h @@ -137,6 +137,11 @@ public: return pResult; } + void operator delete(void *p) + { + MemAlloc_Free( p ); + }; + private: CAI_BaseNPC *m_pOuter; }; diff --git a/game/server/func_areaportal.cpp b/game/server/func_areaportal.cpp index ca391317..321da0f8 100644 --- a/game/server/func_areaportal.cpp +++ b/game/server/func_areaportal.cpp @@ -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 ); diff --git a/mathlib/polyhedron.cpp b/mathlib/polyhedron.cpp index 54e243ff..f02bba6f 100644 --- a/mathlib/polyhedron.cpp +++ b/mathlib/polyhedron.cpp @@ -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; diff --git a/public/mathlib/polyhedron.h b/public/mathlib/polyhedron.h index 38b465c7..8f4a4955 100644 --- a/public/mathlib/polyhedron.h +++ b/public/mathlib/polyhedron.h @@ -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: diff --git a/public/studio.h b/public/studio.h index f67a78cc..17bb0659 100644 --- a/public/studio.h +++ b/public/studio.h @@ -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); diff --git a/studiorender/studiorendercontext.cpp b/studiorender/studiorendercontext.cpp index 2d857da3..c29a27b6 100644 --- a/studiorender/studiorendercontext.cpp +++ b/studiorender/studiorendercontext.cpp @@ -1317,7 +1317,7 @@ void CStudioRenderContext::R_StudioDestroyStaticMeshes( int numStudioMeshes, stu if ( *ppStudioMeshes ) { - delete *ppStudioMeshes; + delete[] *ppStudioMeshes; *ppStudioMeshes = 0; } } diff --git a/vpklib/packedstore.cpp b/vpklib/packedstore.cpp index 8b7d7ba7..33f28b56 100644 --- a/vpklib/packedstore.cpp +++ b/vpklib/packedstore.cpp @@ -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 ) {