Skip to content

Commit

Permalink
fix address sanitizer issues nillerusr#2
Browse files Browse the repository at this point in the history
  • Loading branch information
nillerusr committed May 1, 2022
1 parent ce68fff commit 61cd8d0
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 91 deletions.
2 changes: 1 addition & 1 deletion engine/audio/private/voice_record_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class VoiceRecord_SDL : public IVoiceRecord
void audioRecordingCallback( void *userdata, uint8 *stream, int len )
{
VoiceRecord_SDL *voice = (VoiceRecord_SDL*)userdata;
voice->RenderBuffer( stream, len );
voice->RenderBuffer( (char*)stream, len );
}

VoiceRecord_SDL::VoiceRecord_SDL() :
Expand Down
2 changes: 1 addition & 1 deletion engine/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2751,7 +2751,7 @@ void CL_InitLanguageCvar()
else if( szLang )
{
ELanguage lang = PchLanguageICUCodeToELanguage(szLang, k_Lang_English);
char *szShortLang = GetLanguageShortName(lang);
const char *szShortLang = GetLanguageShortName(lang);
cl_language.SetValue( szShortLang );
}
else
Expand Down
6 changes: 3 additions & 3 deletions engine/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,14 +1816,14 @@ void CClientState::FinishSignonState_New()
//
// This is pretty janky, but doesn't really have any cost (and even makes our one-frozen-frame load screen slightly
// less likely to trigger OS "not responding" warnings)
extern void V_RenderVGuiOnly();
V_RenderVGuiOnly();
// extern void V_RenderVGuiOnly();
// V_RenderVGuiOnly();

// Before we do anything with the whitelist, make sure we have the proper map pack mounted
// this will load the .bsp by setting the world model the string list at the hardcoded index 1.
cl.SetModel( 1 );

V_RenderVGuiOnly();
//V_RenderVGuiOnly();

// Check for a new whitelist. It's good to do it early in the connection process here because if we wait until later,
// the client may have loaded some files w/o the proper whitelist restrictions and we'd have to reload them.
Expand Down
1 change: 1 addition & 0 deletions engine/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ CConPanel::CConPanel( vgui::Panel *parent ) : CBasePanel( parent, "CConPanel" )
//-----------------------------------------------------------------------------
CConPanel::~CConPanel( void )
{
g_pConPanel = NULL;
}

void CConPanel::Con_NPrintf( int idx, const char *msg )
Expand Down
2 changes: 1 addition & 1 deletion engine/saverestore_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ class CSaveRestoreFileSystemPassthrough : public ISaveRestoreFileSystem

SaveMsg( "DirectoryCopy: AsyncAppend %s, %s\n", szName, pDestFileName );
g_pFileSystem->AsyncAppend( pDestFileName, memcpy( new char[MAX_PATH], list[i].szFileName, MAX_PATH), MAX_PATH, true ); // Filename can only be as long as a map name + extension
g_pFileSystem->AsyncAppend( pDestFileName, new int(fileSize), sizeof(int), true );
g_pFileSystem->AsyncAppend( pDestFileName, memcpy( new char[sizeof(int)], &fileSize, sizeof(int)), sizeof(int), true );
g_pFileSystem->AsyncAppendFile( pDestFileName, szName );
}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/shadowmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2071,11 +2071,11 @@ class CClipPlane


private:
static const Vector m_pNormal;
static Vector m_pNormal;
static float m_Dist;
};

const Vector CClipPlane::m_pNormal;
Vector CClipPlane::m_pNormal;
float CClipPlane::m_Dist;

static inline void ClampTexCoord( ShadowVertex_t *pInVertex, ShadowVertex_t *pOutVertex )
Expand Down
2 changes: 2 additions & 0 deletions materialsystem/cmaterial_queuefriendly.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
class CMaterial_QueueFriendly : public IMaterialInternal //wraps a CMaterial with queue friendly functions for game/engine code. materialsystem/shaderapi code should use CMaterial directly.
{
public:
CMaterial_QueueFriendly() : m_pRealTimeVersion(NULL) {}

virtual const char * GetName() const;
virtual const char * GetTextureGroupName() const;
virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent ) const;
Expand Down
60 changes: 29 additions & 31 deletions materialsystem/shaderapidx9/shaderapidx8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6301,27 +6301,16 @@ int CShaderAPIDx8::GetCurrentDynamicVBSize( void )

FORCEINLINE void CShaderAPIDx8::SetVertexShaderConstantInternal( int var, float const* pVec, int numVecs, bool bForce )
{
Assert( numVecs > 0 );
Assert( pVec );

// DX8 asm shaders use a constant mapping which has transforms and vertex shader
// specific constants shifted down by 10 constants (two 5-constant light structures)
if ( IsPC() )
if ( IsPC() || IsPS3() )
{
if ( (g_pHardwareConfig->Caps().m_nDXSupportLevel < 90) && (var >= VERTEX_SHADER_MODULATION_COLOR) )
{
var -= 10;
}
Assert( var + numVecs <= g_pHardwareConfig->NumVertexShaderConstants() );

if ( !bForce )
{
int skip = 0;
numVecs = AdjustUpdateRange( pVec, &m_DesiredState.m_pVectorVertexShaderConstant[var], numVecs, &skip );
if ( !numVecs )
return;
var += skip;
pVec += skip * 4;
}
if ( !bForce && memcmp( pVec, &m_DynamicState.m_pVectorVertexShaderConstant[var], numVecs * 4 * sizeof( float ) ) == 0 )
return;

Dx9Device()->SetVertexShaderConstantF( var, pVec, numVecs );
memcpy( &m_DynamicState.m_pVectorVertexShaderConstant[var], pVec, numVecs * 4 * sizeof(float) );
}
Expand All @@ -6330,12 +6319,10 @@ FORCEINLINE void CShaderAPIDx8::SetVertexShaderConstantInternal( int var, float
Assert( var + numVecs <= g_pHardwareConfig->NumVertexShaderConstants() );
}

memcpy( &m_DesiredState.m_pVectorVertexShaderConstant[var], pVec, numVecs * 4 * sizeof(float) );
if ( IsX360() && var + numVecs > m_MaxVectorVertexShaderConstant )
m_MaxVectorVertexShaderConstant = var + numVecs;

if ( IsX360() )
{
m_MaxVectorVertexShaderConstant = max( m_MaxVectorVertexShaderConstant, var + numVecs );
}
memcpy( &m_DesiredState.m_pVectorVertexShaderConstant[var], pVec, numVecs * 4 * sizeof(float) );
}


Expand Down Expand Up @@ -6417,29 +6404,40 @@ FORCEINLINE void CShaderAPIDx8::SetPixelShaderConstantInternal( int nStartConst,
{
Assert( nStartConst + nNumConsts <= g_pHardwareConfig->NumPixelShaderConstants() );

if ( IsPC() )
if ( IsPC() || IsPS3() )
{
if ( ! bForce )
if ( !bForce )
{
int skip = 0;
nNumConsts = AdjustUpdateRange( pValues, &m_DesiredState.m_pVectorPixelShaderConstant[nStartConst], nNumConsts, &skip );
DWORD* pSrc = (DWORD*)pValues;
DWORD* pDst = (DWORD*)&m_DesiredState.m_pVectorPixelShaderConstant[nStartConst];
while( nNumConsts && ( pSrc[0] == pDst[0] ) && ( pSrc[1] == pDst[1] ) && ( pSrc[2] == pDst[2] ) && ( pSrc[3] == pDst[3] ) )
{
pSrc += 4;
pDst += 4;
nNumConsts--;
nStartConst++;
}
if ( !nNumConsts )
return;
nStartConst += skip;
pValues += skip * 4;
pValues = reinterpret_cast< float const * >( pSrc );
}

Dx9Device()->SetPixelShaderConstantF( nStartConst, pValues, nNumConsts );
memcpy( &m_DynamicState.m_pVectorPixelShaderConstant[nStartConst], pValues, nNumConsts * 4 * sizeof(float) );
}

memcpy( &m_DesiredState.m_pVectorPixelShaderConstant[nStartConst], pValues, nNumConsts * 4 * sizeof(float) );

if ( IsX360() )
if ( IsX360() && nStartConst + nNumConsts > m_MaxVectorPixelShaderConstant )
{
m_MaxVectorPixelShaderConstant = max( m_MaxVectorPixelShaderConstant, nStartConst + nNumConsts );
m_MaxVectorPixelShaderConstant = nStartConst + nNumConsts;
Assert( m_MaxVectorPixelShaderConstant <= 32 );
if ( m_MaxVectorPixelShaderConstant > 32 )
{
// NOTE! There really are 224 pixel shader constants on the 360, but we do an optimization that only blasts the first 32 always.
Error( "Don't use more then the first 32 pixel shader constants on the 360!" );
}
}

memcpy( &m_DesiredState.m_pVectorPixelShaderConstant[nStartConst], pValues, nNumConsts * 4 * sizeof(float) );
}

void CShaderAPIDx8::SetPixelShaderConstant( int var, float const* pVec, int numVecs, bool bForce )
Expand Down
2 changes: 1 addition & 1 deletion materialsystem/shaderapidx9/shaderdevicedx8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ void CShaderDeviceMgrDx8::CheckVendorDependentAlphaToCoverage( HardwareCaps_t *p
ConVar mat_hdr_level( "mat_hdr_level", "2", FCVAR_ARCHIVE );
ConVar mat_slopescaledepthbias_shadowmap( "mat_slopescaledepthbias_shadowmap", "16", FCVAR_CHEAT );
#ifdef DX_TO_GL_ABSTRACTION
ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "20", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "40", FCVAR_CHEAT );
#else
ConVar mat_depthbias_shadowmap( "mat_depthbias_shadowmap", "0.0005", FCVAR_CHEAT );
#endif
Expand Down
2 changes: 1 addition & 1 deletion materialsystem/stdshaders/depthwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ BEGIN_VS_SHADER_FLAGS( DepthWrite, "Help for Depth Write", SHADER_NOT_EDITABLE )
vParms.y = 4000.0f; // arbitrary far
vParms.z = 0.0f;
vParms.w = 0.0f;
pShaderAPI->SetPixelShaderConstant( 1, vParms.Base(), 2 );
pShaderAPI->SetPixelShaderConstant( 1, vParms.Base(), 1 );

} // DYNAMIC_STATE

Expand Down
7 changes: 4 additions & 3 deletions materialsystem/stdshaders/particlesphere_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ BEGIN_VS_SHADER_FLAGS( ParticleSphere_DX9, "Help for BumpmappedEnvMap", SHADER_N
// (It does this by seeing if the intensity*1/distSqr is > 1. If so, then it scales it so
// it is equal to 1).
const float *f = params[LIGHT_COLOR]->GetVecValue();
Vector vLightColor( f[0], f[1], f[2] );
Vector4D vLightColor( f[0], f[1], f[2], 0.f );
float flScale = max( vLightColor.x, max( vLightColor.y, vLightColor.z ) );
if ( flScale < 0.01f )
flScale = 0.01f;
float vScaleVec[3] = { flScale, flScale, flScale };

Vector4D vScaleVec = { flScale, flScale, flScale, 0.f };
vLightColor /= flScale;

pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_1, vLightColor.Base() );
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec );
pShaderAPI->SetVertexShaderConstant( VERTEX_SHADER_SHADER_SPECIFIC_CONST_2, vScaleVec.Base() );

pShaderAPI->SetPixelShaderFogParams( PSREG_FOG_PARAMS );

Expand Down
10 changes: 7 additions & 3 deletions public/collisionutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,14 +635,18 @@ bool IsOBBIntersectingOBB( const Vector &vecOrigin1, const QAngle &vecAngles1, c
}

// NOTE: This is only very slightly faster on high end PCs and x360

#ifdef __SANITIZE_ADDRESS__
#define USE_SIMD_RAY_CHECKS 0
#else
#define USE_SIMD_RAY_CHECKS 1
#endif
//-----------------------------------------------------------------------------
// returns true if there's an intersection between box and ray
//-----------------------------------------------------------------------------
bool FASTCALL IsBoxIntersectingRay( const Vector& boxMin, const Vector& boxMax,
const Vector& origin, const Vector& vecDelta, float flTolerance )
{

#if USE_SIMD_RAY_CHECKS
// Load the unaligned ray/box parameters into SIMD registers
fltx4 start = LoadUnaligned3SIMD(origin.Base());
Expand Down Expand Up @@ -695,7 +699,7 @@ bool FASTCALL IsBoxIntersectingRay( const Vector& boxMin, const Vector& boxMax,
return IsAllZeros(separation);
#else
// On the x360, we force use of the SIMD functions.
#if defined(_X360)
#if defined(_X360)
if (IsX360())
{
fltx4 delta = LoadUnaligned3SIMD(vecDelta.Base());
Expand Down Expand Up @@ -766,7 +770,7 @@ bool FASTCALL IsBoxIntersectingRay( const Vector& boxMin, const Vector& boxMax,
bool FASTCALL IsBoxIntersectingRay( const Vector& boxMin, const Vector& boxMax,
const Vector& origin, const Vector& vecDelta,
const Vector& vecInvDelta, float flTolerance )
{
{
#if USE_SIMD_RAY_CHECKS
// Load the unaligned ray/box parameters into SIMD registers
fltx4 start = LoadUnaligned3SIMD(origin.Base());
Expand Down
2 changes: 1 addition & 1 deletion public/datamap.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class CDatadescGeneratedNameHolder
{
for ( int i = 0; i < m_Names.Count(); i++ )
{
delete m_Names[i];
delete[] m_Names[i];
}
}

Expand Down
2 changes: 1 addition & 1 deletion public/dispcoll_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void CDispCollTree::AABBTree_CreateLeafs( void )
}
}

void CDispCollTree::AABBTree_GenerateBoxes_r( int nodeIndex, Vector *pMins, Vector *pMaxs )
void __attribute__((no_sanitize("address"))) CDispCollTree::AABBTree_GenerateBoxes_r( int nodeIndex, Vector *pMins, Vector *pMaxs )
{
// leaf
ClearBounds( *pMins, *pMaxs );
Expand Down
4 changes: 1 addition & 3 deletions public/icvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ inline ConCommandBase * ICvar::Iterator::Get( void )
// don't have to include tier1.h
//-----------------------------------------------------------------------------

// These are marked DLL_EXPORT for Linux.
DLL_EXPORT ICvar *cvar;
extern ICvar *cvar;
extern ICvar *g_pCVar;


#endif // ICVAR_H
2 changes: 1 addition & 1 deletion public/mathlib/ssemath.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define USE_STDC_FOR_SIMD 0
#endif

#if (!defined (__arm__) && !defined(_X360) && (USE_STDC_FOR_SIMD == 0))
#if !(defined(_X360) && (USE_STDC_FOR_SIMD == 0))
#define _SSE1 1
#endif

Expand Down
2 changes: 1 addition & 1 deletion public/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Studio models are position independent, so the cache manager can move them.
#define MAXSTUDIOFLEXDESC 1024 // maximum number of low level flexes (actual morph targets)
#define MAXSTUDIOFLEXCTRL 96 // maximum number of flexcontrollers (input sliders)
#define MAXSTUDIOPOSEPARAM 24
#define MAXSTUDIOBONECTRLS 4
#define MAXSTUDIOBONECTRLS 5
#define MAXSTUDIOANIMBLOCKS 256

#define MAXSTUDIOBONEBITS 7 // NOTE: MUST MATCH MAXSTUDIOBONES
Expand Down
23 changes: 17 additions & 6 deletions public/tier0/threadtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,11 @@ class PLATFORM_CLASS CThreadRWLock
class ALIGN8 PLATFORM_CLASS CThreadSpinRWLock
{
public:
CThreadSpinRWLock() { COMPILE_TIME_ASSERT( sizeof( LockInfo_t ) == sizeof( int64 ) ); Assert( (intp)this % 8 == 0 ); memset( this, 0, sizeof( *this ) ); }
CThreadSpinRWLock()
{
COMPILE_TIME_ASSERT( sizeof( LockInfo_t ) == sizeof( int64 ) );
Assert( (intp)this % 8 == 0 );
}

bool TryLockForWrite();
bool TryLockForRead();
Expand All @@ -1200,11 +1204,18 @@ class ALIGN8 PLATFORM_CLASS CThreadSpinRWLock
void UnlockWrite() const { const_cast<CThreadSpinRWLock *>(this)->UnlockWrite(); }

private:

struct LockInfo_t
{
LockInfo_t(uint32 thread_id = 0, int readers = 0)
{
uint32 m_writerId;
int m_nReaders;
};
m_writerId = thread_id;
m_nReaders = readers;
}

uint32 m_writerId;
int m_nReaders;
};

bool AssignIf( const LockInfo_t &newValue, const LockInfo_t &comperand );
bool TryLockForWrite( const uint32 threadId );
Expand Down Expand Up @@ -1751,8 +1762,8 @@ inline bool CThreadSpinRWLock::TryLockForWrite( const uint32 threadId )
return false;
}

static const LockInfo_t oldValue = { 0, 0 };
LockInfo_t newValue = { threadId, 0 };
static const LockInfo_t oldValue( 0, 0 );
LockInfo_t newValue( threadId, 0 );
const bool bSuccess = AssignIf( newValue, oldValue );
#if defined(_X360)
if ( bSuccess )
Expand Down
2 changes: 1 addition & 1 deletion public/tier0/tslist.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class CTSListBase
#endif
}

TSLNodeBase_t *Pop()
__attribute__((no_sanitize("address"))) TSLNodeBase_t *Pop()
{
#ifdef USE_NATIVE_SLIST
#ifdef _X360
Expand Down
3 changes: 1 addition & 2 deletions public/tier1/tier1.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class IProcessUtils;
// allowing link libraries to access tier1 library interfaces
//-----------------------------------------------------------------------------

// These are marked DLL_EXPORT for Linux.
DLL_EXPORT ICvar *cvar;
extern ICvar *cvar;
extern ICvar *g_pCVar;
extern IProcessUtils *g_pProcessUtils;

Expand Down
Loading

0 comments on commit 61cd8d0

Please sign in to comment.