From df9d8cf0ce4cb7a0790199e5355bb499a4a63ab0 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 11:44:50 +0200 Subject: [PATCH 01/13] Don't use memcpy in idMat2 constructor --- neo/idlib/math/Matrix.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index 77b0adc3..93771940 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -134,7 +134,8 @@ ID_INLINE idMat2::idMat2( const float xx, const float xy, const float yx, const } ID_INLINE idMat2::idMat2( const float src[ 2 ][ 2 ] ) { - memcpy( mat, src, 2 * 2 * sizeof( float ) ); + mat[0].x = src[0][0]; mat[0].y = src[0][1]; + mat[1].x = src[1][0]; mat[1].y = src[1][1]; } ID_INLINE const idVec2 &idMat2::operator[]( int index ) const { From c67c4551807fdd61a279c035e67a28823483bcd1 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 11:50:21 +0200 Subject: [PATCH 02/13] Don't use memcpy in idMat3 constructor --- neo/idlib/math/Matrix.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index 93771940..dbfff6d8 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -439,7 +439,9 @@ ID_INLINE idMat3::idMat3( const float xx, const float xy, const float xz, const } ID_INLINE idMat3::idMat3( const float src[ 3 ][ 3 ] ) { - memcpy( mat, src, 3 * 3 * sizeof( float ) ); + mat[0].x = src[0][0]; mat[0].y = src[0][1]; mat[0].z = src[0][2]; + mat[1].x = src[1][0]; mat[1].y = src[1][1]; mat[1].z = src[1][2]; + mat[2].x = src[2][0]; mat[2].y = src[2][1]; mat[2].z = src[2][2]; } ID_INLINE const idVec3 &idMat3::operator[]( int index ) const { From 37ed3e9e46cc96ffa75931f64b51c09ade457691 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:11:32 +0200 Subject: [PATCH 03/13] Don't use memset in idMat3::Zero --- neo/idlib/math/Matrix.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index dbfff6d8..fa8b1339 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -598,7 +598,9 @@ ID_INLINE bool idMat3::operator!=( const idMat3 &a ) const { } ID_INLINE void idMat3::Zero( void ) { - memset( mat, 0, sizeof( idMat3 ) ); + mat[0].x = 0.0f; mat[0].y = 0.0f; mat[0].z = 0.0f; + mat[1].x = 0.0f; mat[1].y = 0.0f; mat[1].z = 0.0f; + mat[2].x = 0.0f; mat[2].y = 0.0f; mat[2].z = 0.0f; } ID_INLINE void idMat3::Identity( void ) { From 57f09de425a1beae0ac4fc21326b64b5a77aad2c Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:16:12 +0200 Subject: [PATCH 04/13] Don't use memcpy in idMat4 constructor --- neo/idlib/math/Matrix.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index fa8b1339..6c53f4d0 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -886,7 +886,10 @@ ID_INLINE idMat4::idMat4( const idMat3 &rotation, const idVec3 &translation ) { } ID_INLINE idMat4::idMat4( const float src[ 4 ][ 4 ] ) { - memcpy( mat, src, 4 * 4 * sizeof( float ) ); + mat[0].x = src[0][0]; mat[0].y = src[0][1]; mat[0].z = src[0][2]; mat[0].w = src[0][3]; + mat[1].x = src[1][0]; mat[1].y = src[1][1]; mat[1].z = src[1][2]; mat[1].w = src[1][3]; + mat[2].x = src[2][0]; mat[2].y = src[2][1]; mat[2].z = src[2][2]; mat[2].w = src[2][3]; + mat[3].x = src[3][0]; mat[3].y = src[3][1]; mat[3].z = src[3][2]; mat[3].w = src[3][3]; } ID_INLINE const idVec4 &idMat4::operator[]( int index ) const { From 8fa37934107d25379fcc94a31047577e895323f0 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:19:13 +0200 Subject: [PATCH 05/13] Don't use memset in idMat4::Zero --- neo/idlib/math/Matrix.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index 6c53f4d0..df5628dd 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -1065,7 +1065,10 @@ ID_INLINE bool idMat4::operator!=( const idMat4 &a ) const { } ID_INLINE void idMat4::Zero( void ) { - memset( mat, 0, sizeof( idMat4 ) ); + mat[0].x = 0.0f; mat[0].y = 0.0f; mat[0].z = 0.0f; mat[0].w = 0.0f; + mat[1].x = 0.0f; mat[1].y = 0.0f; mat[1].z = 0.0f; mat[1].w = 0.0f; + mat[2].x = 0.0f; mat[2].y = 0.0f; mat[2].z = 0.0f; mat[2].w = 0.0f; + mat[3].x = 0.0f; mat[3].y = 0.0f; mat[3].z = 0.0f; mat[3].w = 0.0f; } ID_INLINE void idMat4::Identity( void ) { From 6a7bb7e305b5408ce0ebb52121a405fb75ef44d5 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:24:05 +0200 Subject: [PATCH 06/13] Don't use memcpy in idMat5 constructor --- neo/idlib/math/Matrix.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index df5628dd..960cb4ca 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -1230,7 +1230,11 @@ ID_INLINE idMat5::idMat5( void ) { } ID_INLINE idMat5::idMat5( const float src[ 5 ][ 5 ] ) { - memcpy( mat, src, 5 * 5 * sizeof( float ) ); + mat[0].x = src[0][0]; mat[0].y = src[0][1]; mat[0].z = src[0][2]; mat[0].s = src[0][3]; mat[0].t = src[0][4]; + mat[1].x = src[1][0]; mat[1].y = src[1][1]; mat[1].z = src[1][2]; mat[1].s = src[1][3]; mat[1].t = src[1][4]; + mat[2].x = src[2][0]; mat[2].y = src[2][1]; mat[2].z = src[2][2]; mat[2].s = src[2][3]; mat[2].t = src[2][4]; + mat[3].x = src[3][0]; mat[3].y = src[3][1]; mat[3].z = src[3][2]; mat[3].s = src[3][3]; mat[3].t = src[3][4]; + mat[4].x = src[4][0]; mat[4].y = src[4][1]; mat[4].z = src[4][2]; mat[4].s = src[4][3]; mat[4].t = src[4][4]; } ID_INLINE idMat5::idMat5( const idVec5 &v0, const idVec5 &v1, const idVec5 &v2, const idVec5 &v3, const idVec5 &v4 ) { From 669e259787a7a963b1eee36b9fa7577e80946ede Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:29:11 +0200 Subject: [PATCH 07/13] Don't use memset in idMat5::Zero --- neo/idlib/math/Matrix.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index 960cb4ca..4e4e3970 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -1397,7 +1397,11 @@ ID_INLINE bool idMat5::operator!=( const idMat5 &a ) const { } ID_INLINE void idMat5::Zero( void ) { - memset( mat, 0, sizeof( idMat5 ) ); + mat[0].x = 0.0f; mat[0].y = 0.0f; mat[0].z = 0.0f; mat[0].s = 0.0f; mat[0].t = 0.0f; + mat[1].x = 0.0f; mat[1].y = 0.0f; mat[1].z = 0.0f; mat[1].s = 0.0f; mat[1].t = 0.0f; + mat[2].x = 0.0f; mat[2].y = 0.0f; mat[2].z = 0.0f; mat[2].s = 0.0f; mat[2].t = 0.0f; + mat[3].x = 0.0f; mat[3].y = 0.0f; mat[3].z = 0.0f; mat[3].s = 0.0f; mat[3].t = 0.0f; + mat[4].x = 0.0f; mat[4].y = 0.0f; mat[4].z = 0.0f; mat[4].s = 0.0f; mat[4].t = 0.0f; } ID_INLINE void idMat5::Identity( void ) { From 30175c72ae20a8704af5220a7e191d105ee6bf91 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:31:54 +0200 Subject: [PATCH 08/13] Be more careful with memcpy in idMat6 constructor --- neo/idlib/math/Matrix.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index 4e4e3970..eb6bca4e 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -1555,7 +1555,12 @@ ID_INLINE idMat6::idMat6( const idVec6 &v0, const idVec6 &v1, const idVec6 &v2, } ID_INLINE idMat6::idMat6( const float src[ 6 ][ 6 ] ) { - memcpy( mat, src, 6 * 6 * sizeof( float ) ); + memcpy( mat[0].ToFloatPtr(), src[0], 6 * sizeof( float ) ); + memcpy( mat[1].ToFloatPtr(), src[1], 6 * sizeof( float ) ); + memcpy( mat[2].ToFloatPtr(), src[2], 6 * sizeof( float ) ); + memcpy( mat[3].ToFloatPtr(), src[3], 6 * sizeof( float ) ); + memcpy( mat[4].ToFloatPtr(), src[4], 6 * sizeof( float ) ); + memcpy( mat[5].ToFloatPtr(), src[5], 6 * sizeof( float ) ); } ID_INLINE const idVec6 &idMat6::operator[]( int index ) const { From 8d2d41345d4c420b8bcb9e069fec904cbef41a98 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 12:35:03 +0200 Subject: [PATCH 09/13] Don't use memset in idMat6::Zero --- neo/idlib/math/Matrix.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neo/idlib/math/Matrix.h b/neo/idlib/math/Matrix.h index eb6bca4e..896c0569 100644 --- a/neo/idlib/math/Matrix.h +++ b/neo/idlib/math/Matrix.h @@ -1723,7 +1723,9 @@ ID_INLINE bool idMat6::operator!=( const idMat6 &a ) const { } ID_INLINE void idMat6::Zero( void ) { - memset( mat, 0, sizeof( idMat6 ) ); + for (int i = 0; i < 6; i++) { + mat[i].Zero(); + } } ID_INLINE void idMat6::Identity( void ) { From 59940c9b2fcb925d74133b8c6c1db9d2bc3d00dd Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 13:00:48 +0200 Subject: [PATCH 10/13] Don't memcpy non-trivial type idDrawVert in idSurface constructor --- neo/idlib/geometry/Surface.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/neo/idlib/geometry/Surface.h b/neo/idlib/geometry/Surface.h index 983bce27..b88e3ab7 100644 --- a/neo/idlib/geometry/Surface.h +++ b/neo/idlib/geometry/Surface.h @@ -123,7 +123,9 @@ idSurface::idSurface ID_INLINE idSurface::idSurface( const idDrawVert *verts, const int numVerts, const int *indexes, const int numIndexes ) { assert( verts != NULL && indexes != NULL && numVerts > 0 && numIndexes > 0 ); this->verts.SetNum( numVerts ); - memcpy( this->verts.Ptr(), verts, numVerts * sizeof( verts[0] ) ); + for (int i = 0; i < numVerts; i++) { + this->verts[i] = verts[i]; + } this->indexes.SetNum( numIndexes ); memcpy( this->indexes.Ptr(), indexes, numIndexes * sizeof( indexes[0] ) ); GenerateEdgeIndexes(); From 1ae9ff7d74e5e33c0d11de18f61caae7bdd3785b Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 13:03:48 +0200 Subject: [PATCH 11/13] Don't use memset to zero non-trivial type volumeIntegrals_t --- neo/idlib/geometry/TraceModel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/neo/idlib/geometry/TraceModel.cpp b/neo/idlib/geometry/TraceModel.cpp index b1a88ff2..56e09582 100644 --- a/neo/idlib/geometry/TraceModel.cpp +++ b/neo/idlib/geometry/TraceModel.cpp @@ -1409,7 +1409,10 @@ void idTraceModel::VolumeIntegrals( struct volumeIntegrals_s &integrals ) const int i, a, b, c; float nx, ny, nz; - memset( &integrals, 0, sizeof(volumeIntegrals_t) ); + integrals.T0 = 0.0f; + integrals.T1.Zero(); + integrals.T2.Zero(); + integrals.TP.Zero(); for ( i = 0; i < numPolys; i++ ) { poly = &polys[i]; From 8cfeb51b841257867902f388195c35620b0da238 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 13:07:04 +0200 Subject: [PATCH 12/13] Silence an uninitialized variable warning --- neo/idlib/geometry/TraceModel.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/neo/idlib/geometry/TraceModel.cpp b/neo/idlib/geometry/TraceModel.cpp index 56e09582..62dd2734 100644 --- a/neo/idlib/geometry/TraceModel.cpp +++ b/neo/idlib/geometry/TraceModel.cpp @@ -1164,6 +1164,7 @@ int idTraceModel::GetOrderedSilhouetteEdges( const int edgeIsSilEdge[MAX_TRACEMO int i, j, edgeNum, numSilEdges, nextSilVert; int unsortedSilEdges[MAX_TRACEMODEL_EDGES]; + unsortedSilEdges[0] = 0; numSilEdges = 0; for ( i = 1; i <= numEdges; i++ ) { if ( edgeIsSilEdge[i] ) { From 7aee2af217a176c46f9ba52f129f5d9f9357b279 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Mon, 25 Jan 2021 13:25:37 +0200 Subject: [PATCH 13/13] Silence misleading indentation warnings --- neo/renderer/Cinematic.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neo/renderer/Cinematic.cpp b/neo/renderer/Cinematic.cpp index 1b207942..daa1c105 100644 --- a/neo/renderer/Cinematic.cpp +++ b/neo/renderer/Cinematic.cpp @@ -939,8 +939,8 @@ unsigned short idCinematicLocal::yuv_to_rgb( int y, int u, int v ) { g = (YY + ROQ_UG_tab[u] + ROQ_VG_tab[v]) >> 8; b = (YY + ROQ_UB_tab[u]) >> 9; - if (r<0) r = 0; if (g<0) g = 0; if (b<0) b = 0; - if (r > 31) r = 31; if (g > 63) g = 63; if (b > 31) b = 31; + if (r <0 ) { r = 0; } if (g < 0) { g = 0; } if (b < 0) { b = 0; } + if (r > 31) { r = 31; } if (g > 63) { g = 63; } if (b > 31) { b = 31; } return (unsigned short)((r<<11)+(g<<5)+(b)); } @@ -957,8 +957,8 @@ unsigned int idCinematicLocal::yuv_to_rgb24( int y, int u, int v ) { g = (YY + ROQ_UG_tab[u] + ROQ_VG_tab[v]) >> 6; b = (YY + ROQ_UB_tab[u]) >> 6; - if (r<0) r = 0; if (g<0) g = 0; if (b<0) b = 0; - if (r > 255) r = 255; if (g > 255) g = 255; if (b > 255) b = 255; + if (r < 0) { r = 0; } if (g < 0) { g = 0; } if (b < 0) { b = 0; } + if (r > 255) { r = 255; } if (g > 255) { g = 255; } if (b > 255) { b = 255; } return LittleInt((r)+(g<<8)+(b<<16)); }