From 2a85b731107d09fff4d99aafcb06557c14c62dad Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 22 Jun 2021 22:39:02 +0200 Subject: [PATCH] Fix some ubsan warnings --- neo/game/SmokeParticles.cpp | 2 +- neo/renderer/tr_light.cpp | 3 ++- neo/renderer/tr_trisurf.cpp | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/neo/game/SmokeParticles.cpp b/neo/game/SmokeParticles.cpp index e63307d4..b0867a72 100644 --- a/neo/game/SmokeParticles.cpp +++ b/neo/game/SmokeParticles.cpp @@ -207,7 +207,7 @@ bool idSmokeParticles::EmitSmoke( const idDeclParticle *smoke, const int systemS int finalParticleTime = stage->cycleMsec * stage->spawnBunching; int deltaMsec = gameLocal.time - systemStartTime; - int nowCount, prevCount; + int nowCount=0, prevCount=0; if ( finalParticleTime == 0 ) { // if spawnBunching is 0, they will all come out at once if ( gameLocal.time == systemStartTime ) { diff --git a/neo/renderer/tr_light.cpp b/neo/renderer/tr_light.cpp index 5a681994..59e4dfb3 100644 --- a/neo/renderer/tr_light.cpp +++ b/neo/renderer/tr_light.cpp @@ -1217,7 +1217,8 @@ void R_AddDrawSurf( const srfTriangles_t *tri, const viewEntity_t *space, const tr.viewDef->maxDrawSurfs *= 2; } tr.viewDef->drawSurfs = (drawSurf_t **)R_FrameAlloc( tr.viewDef->maxDrawSurfs * sizeof( tr.viewDef->drawSurfs[0] ) ); - memcpy( tr.viewDef->drawSurfs, old, count ); + if(count > 0) + memcpy( tr.viewDef->drawSurfs, old, count ); // XXX null pointer passed as argument 2, which is declared to never be null } tr.viewDef->drawSurfs[tr.viewDef->numDrawSurfs] = drawSurf; tr.viewDef->numDrawSurfs++; diff --git a/neo/renderer/tr_trisurf.cpp b/neo/renderer/tr_trisurf.cpp index fd4b2642..2080c094 100644 --- a/neo/renderer/tr_trisurf.cpp +++ b/neo/renderer/tr_trisurf.cpp @@ -813,8 +813,12 @@ void R_CreateDupVerts( srfTriangles_t *tri ) { } } - tri->dupVerts = triDupVertAllocator.Alloc( tri->numDupVerts * 2 ); - memcpy( tri->dupVerts, tempDupVerts, tri->numDupVerts * 2 * sizeof( tri->dupVerts[0] ) ); + if(tri->numDupVerts > 0) { + tri->dupVerts = triDupVertAllocator.Alloc( tri->numDupVerts * 2 ); + memcpy( tri->dupVerts, tempDupVerts, tri->numDupVerts * 2 * sizeof( tri->dupVerts[0] ) ); // runtime error: null pointer passed as argument 1, which is declared to never be null + } else { + tri->dupVerts = NULL; + } } /* @@ -1112,8 +1116,12 @@ void R_IdentifySilEdges( srfTriangles_t *tri, bool omitCoplanarEdges ) { } tri->numSilEdges = numSilEdges; - tri->silEdges = triSilEdgeAllocator.Alloc( numSilEdges ); - memcpy( tri->silEdges, silEdges, numSilEdges * sizeof( tri->silEdges[0] ) ); + if(numSilEdges > 0) { + tri->silEdges = triSilEdgeAllocator.Alloc( numSilEdges ); + memcpy( tri->silEdges, silEdges, numSilEdges * sizeof( tri->silEdges[0] ) ); + } else { + tri->silEdges = NULL; + } } /*