From 6f5c5788ab9306e75c7f1377ed7f2fc2a556e5c4 Mon Sep 17 00:00:00 2001 From: Ensiform Date: Sun, 9 Apr 2023 10:31:45 -0500 Subject: [PATCH] Fixed some errors pointed out by sanitizers and clang --- code/cgame/cg_main.cpp | 2 +- code/client/snd_mem.cpp | 2 +- code/qcommon/cm_polylib.cpp | 8 ++++---- code/qcommon/z_memman_pc.cpp | 10 +++++----- code/rd-vanilla/tr_bsp.cpp | 4 ++-- code/rd-vanilla/tr_model.cpp | 2 +- codeJK2/cgame/cg_main.cpp | 2 +- codemp/client/snd_mem.cpp | 2 +- codemp/qcommon/RoffSystem.cpp | 14 +++++++------- codemp/qcommon/z_memman_pc.cpp | 4 ++-- codemp/rd-vanilla/tr_bsp.cpp | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/code/cgame/cg_main.cpp b/code/cgame/cg_main.cpp index 9823ec8419..86bf1a0c78 100644 --- a/code/cgame/cg_main.cpp +++ b/code/cgame/cg_main.cpp @@ -101,7 +101,7 @@ This is the only way control passes into the cgame module. This must be the very first function compiled into the .q3vm file ================ */ -extern "C" Q_EXPORT intptr_t QDECL vmMain( intptr_t command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7 ) { +extern "C" Q_EXPORT intptr_t QDECL vmMain( int command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7 ) { centity_t *cent; switch ( command ) { diff --git a/code/client/snd_mem.cpp b/code/client/snd_mem.cpp index fb7ea05b2b..97b4f4b4d1 100644 --- a/code/client/snd_mem.cpp +++ b/code/client/snd_mem.cpp @@ -236,7 +236,7 @@ void ResampleSfx (sfx_t *sfx, int iInRate, int iInWidth, byte *pData) if (iInWidth == 2) { iSample = LittleShort ( ((short *)pData)[iSrcSample] ); } else { - iSample = (int)( (unsigned char)(pData[iSrcSample]) - 128) << 8; + iSample = (unsigned int)( (unsigned char)(pData[iSrcSample]) - 128) << 8; } sfx->pSoundData[i] = (short)iSample; diff --git a/code/qcommon/cm_polylib.cpp b/code/qcommon/cm_polylib.cpp index bfdca8fe0c..95d4b6a1ca 100644 --- a/code/qcommon/cm_polylib.cpp +++ b/code/qcommon/cm_polylib.cpp @@ -188,12 +188,12 @@ ChopWindingInPlace void ChopWindingInPlace (winding_t **inout, vec3_t normal, vec_t dist, vec_t epsilon) { winding_t *in; - vec_t dists[MAX_POINTS_ON_WINDING+4]; - int sides[MAX_POINTS_ON_WINDING+4]; + float dists[MAX_POINTS_ON_WINDING+4] = { 0 }; + int sides[MAX_POINTS_ON_WINDING+4] = { 0 }; int counts[3]; - static vec_t dot; // VC 4.2 optimizer bug if not static + static float dot; // VC 4.2 optimizer bug if not static int i, j; - vec_t *p1, *p2; + float *p1, *p2; vec3_t mid; winding_t *f; int maxpts; diff --git a/code/qcommon/z_memman_pc.cpp b/code/qcommon/z_memman_pc.cpp index b2cab8b793..d0051ed635 100644 --- a/code/qcommon/z_memman_pc.cpp +++ b/code/qcommon/z_memman_pc.cpp @@ -993,15 +993,15 @@ Touch all known used data to make sure it is paged in void Com_TouchMemory( void ) { //int start, end; int i, j; - int sum; - int totalTouched; + unsigned int sum; + //int totalTouched; Z_Validate(); //start = Sys_Milliseconds(); sum = 0; - totalTouched=0; + //totalTouched=0; zoneHeader_t *pMemory = TheZone.Header.pNext; while (pMemory) @@ -1009,9 +1009,9 @@ void Com_TouchMemory( void ) { byte *pMem = (byte *) &pMemory[1]; j = pMemory->iSize >> 2; for (i=0; iiSize; + //totalTouched+=pMemory->iSize; pMemory = pMemory->pNext; } diff --git a/code/rd-vanilla/tr_bsp.cpp b/code/rd-vanilla/tr_bsp.cpp index 5ea038d541..afbbb175f6 100644 --- a/code/rd-vanilla/tr_bsp.cpp +++ b/code/rd-vanilla/tr_bsp.cpp @@ -395,7 +395,7 @@ static void ParseFace( dsurface_t *ds, mapVert_t *verts, msurface_t *surf, int * numIndexes = LittleLong( ds->numIndexes ); // create the srfSurfaceFace_t - sfaceSize = ( intptr_t ) &((srfSurfaceFace_t *)0)->points[numPoints]; + sfaceSize = sizeof( *cv ) - sizeof( cv->points ) + sizeof( cv->points[0] ) * numPoints; ofsIndexes = sfaceSize; sfaceSize += sizeof( int ) * numIndexes; @@ -684,7 +684,7 @@ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump, wor { case MST_PLANAR: - int sfaceSize = ( intptr_t ) &((srfSurfaceFace_t *)0)->points[LittleLong(in->numVerts)]; + int sfaceSize = sizeof( srfSurfaceFace_t ) - sizeof( float[1][VERTEXSIZE] ) + sizeof( float[VERTEXSIZE] ) * LittleLong(in->numVerts); sfaceSize += sizeof( int ) * LittleLong(in->numIndexes); iFaceDataSizeRequired += sfaceSize; diff --git a/code/rd-vanilla/tr_model.cpp b/code/rd-vanilla/tr_model.cpp index 9b2d74fdaa..a6d5bc7b34 100644 --- a/code/rd-vanilla/tr_model.cpp +++ b/code/rd-vanilla/tr_model.cpp @@ -768,7 +768,7 @@ qhandle_t RE_RegisterModel( const char *name ) qhandle_t q = RE_RegisterModel_Actual( name ); - if (Q_stricmp(&name[strlen(name)-4],".gla")){ + if (!COM_CompareExtension(name, ".gla")) { gbInsideRegisterModel = qfalse; // GLA files recursively call this, so don't turn off half way. A reference count would be nice, but if any ERR_DROP ever occurs within the load then the refcount will be knackered from then on } diff --git a/codeJK2/cgame/cg_main.cpp b/codeJK2/cgame/cg_main.cpp index 2fb49dd93a..9be003e9a9 100644 --- a/codeJK2/cgame/cg_main.cpp +++ b/codeJK2/cgame/cg_main.cpp @@ -103,7 +103,7 @@ This is the only way control passes into the cgame module. This must be the very first function compiled into the .q3vm file ================ */ -extern "C" Q_EXPORT intptr_t vmMain( intptr_t command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7 ) { +extern "C" Q_EXPORT intptr_t vmMain( int command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7 ) { centity_t *cent; switch ( command ) { diff --git a/codemp/client/snd_mem.cpp b/codemp/client/snd_mem.cpp index 16bcd57daa..8270fc91d6 100644 --- a/codemp/client/snd_mem.cpp +++ b/codemp/client/snd_mem.cpp @@ -236,7 +236,7 @@ void ResampleSfx (sfx_t *sfx, int iInRate, int iInWidth, byte *pData) if (iInWidth == 2) { iSample = LittleShort ( ((short *)pData)[iSrcSample] ); } else { - iSample = (int)( (unsigned char)(pData[iSrcSample]) - 128) << 8; + iSample = (unsigned int)( (unsigned char)(pData[iSrcSample]) - 128) << 8; } sfx->pSoundData[i] = (short)iSample; diff --git a/codemp/qcommon/RoffSystem.cpp b/codemp/qcommon/RoffSystem.cpp index a61e0e3334..bcb14caa4a 100644 --- a/codemp/qcommon/RoffSystem.cpp +++ b/codemp/qcommon/RoffSystem.cpp @@ -869,19 +869,19 @@ qboolean CROFFSystem::ApplyROFF( SROFFEntity *roff_ent, CROFFSystem::CROFF *roff return qtrue; } +#ifndef DEDICATED + vec3_t originTemp, angleTemp; if (roff_ent->mIsClient) { -#ifndef DEDICATED - vec3_t originTemp, angleTemp; originTrajectory = CGVM_GetOriginTrajectory( roff_ent->mEntID ); angleTrajectory = CGVM_GetAngleTrajectory( roff_ent->mEntID ); CGVM_GetOrigin( roff_ent->mEntID, originTemp ); origin = originTemp; CGVM_GetAngles( roff_ent->mEntID, angleTemp ); angle = angleTemp; -#endif } else +#endif { // Find the entity to apply the roff to ent = SV_GentityNum( roff_ent->mEntID ); @@ -982,7 +982,7 @@ void CROFFSystem::ProcessNote(SROFFEntity *roff_ent, char *note) { temp[size++] = note[pos++]; } - temp[size] = 0; + temp[size] = '\0'; if (size) { @@ -1016,19 +1016,19 @@ qboolean CROFFSystem::ClearLerp( SROFFEntity *roff_ent ) trajectory_t *originTrajectory = NULL, *angleTrajectory = NULL; float *origin = NULL, *angle = NULL; +#ifndef DEDICATED + vec3_t originTemp, angleTemp; if (roff_ent->mIsClient) { -#ifndef DEDICATED - vec3_t originTemp, angleTemp; originTrajectory = CGVM_GetOriginTrajectory( roff_ent->mEntID ); angleTrajectory = CGVM_GetAngleTrajectory( roff_ent->mEntID ); CGVM_GetOrigin( roff_ent->mEntID, originTemp ); origin = originTemp; CGVM_GetAngles( roff_ent->mEntID, angleTemp ); angle = angleTemp; -#endif } else +#endif { // Find the entity to apply the roff to ent = SV_GentityNum( roff_ent->mEntID ); diff --git a/codemp/qcommon/z_memman_pc.cpp b/codemp/qcommon/z_memman_pc.cpp index 25f92d4fa7..dff480cf0b 100644 --- a/codemp/qcommon/z_memman_pc.cpp +++ b/codemp/qcommon/z_memman_pc.cpp @@ -666,7 +666,7 @@ Touch all known used data to make sure it is paged in void Com_TouchMemory( void ) { // int start, end; int i, j; - int sum; + unsigned int sum; // start = Sys_Milliseconds(); Z_Validate(); @@ -679,7 +679,7 @@ void Com_TouchMemory( void ) { byte *pMem = (byte *) &pMemory[1]; j = pMemory->iSize >> 2; for (i=0; ipNext; diff --git a/codemp/rd-vanilla/tr_bsp.cpp b/codemp/rd-vanilla/tr_bsp.cpp index a7f42c0cf1..7ce2e82eec 100644 --- a/codemp/rd-vanilla/tr_bsp.cpp +++ b/codemp/rd-vanilla/tr_bsp.cpp @@ -383,7 +383,7 @@ static void ParseFace( dsurface_t *ds, mapVert_t *verts, msurface_t *surf, int * numIndexes = LittleLong( ds->numIndexes ); // create the srfSurfaceFace_t - sfaceSize = ( size_t ) &((srfSurfaceFace_t *)0)->points[numPoints]; + sfaceSize = sizeof( *cv ) - sizeof( cv->points ) + sizeof( cv->points[0] ) * numPoints; ofsIndexes = sfaceSize; sfaceSize += sizeof( int ) * numIndexes;