From 4b5ca31149894108f12477d011abb02fb2b7db03 Mon Sep 17 00:00:00 2001 From: howetuft Date: Sun, 3 Nov 2019 15:34:40 +0100 Subject: [PATCH] Fix -Wclass-memaccess warning Replace C-style memset with C++ value-initialization/assignment (smarter and safer: see https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon3-avoid-bounds-errors) --- .../Mesh/App/WildMagic4/Wm4MeshCurvature.cpp | 6 +-- .../Mesh/App/WildMagic4/Wm4MeshSmoother.cpp | 4 +- src/Mod/Path/libarea/clipper.cpp | 37 +++++++++---------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.cpp b/src/Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.cpp index 9369c93cad..b4403e2a88 100644 --- a/src/Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.cpp +++ b/src/Mod/Mesh/App/WildMagic4/Wm4MeshCurvature.cpp @@ -31,7 +31,7 @@ MeshCurvature::MeshCurvature (int iVQuantity, // compute normal vectors m_akNormal = WM4_NEW Vector3[m_iVQuantity]; - memset(m_akNormal,0,m_iVQuantity*sizeof(Vector3)); + std::fill_n(m_akNormal,m_iVQuantity,Vector3{0,0,0}); int i, iV0, iV1, iV2; for (i = 0; i < m_iTQuantity; i++) { @@ -58,8 +58,8 @@ MeshCurvature::MeshCurvature (int iVQuantity, Matrix3* akDNormal = WM4_NEW Matrix3[m_iVQuantity]; Matrix3* akWWTrn = WM4_NEW Matrix3[m_iVQuantity]; Matrix3* akDWTrn = WM4_NEW Matrix3[m_iVQuantity]; - memset(akWWTrn,0,m_iVQuantity*sizeof(Matrix3)); - memset(akDWTrn,0,m_iVQuantity*sizeof(Matrix3)); + std::fill_n(akWWTrn,m_iVQuantity,Matrix3{0,0,0,0,0,0,0,0,0}); + std::fill_n(akDWTrn,m_iVQuantity,Matrix3{0,0,0,0,0,0,0,0,0}); int iRow, iCol; aiIndex = m_aiIndex; diff --git a/src/Mod/Mesh/App/WildMagic4/Wm4MeshSmoother.cpp b/src/Mod/Mesh/App/WildMagic4/Wm4MeshSmoother.cpp index f9330097de..009a68bcc3 100644 --- a/src/Mod/Mesh/App/WildMagic4/Wm4MeshSmoother.cpp +++ b/src/Mod/Mesh/App/WildMagic4/Wm4MeshSmoother.cpp @@ -89,8 +89,8 @@ void MeshSmoother::Destroy () template void MeshSmoother::Update (Real fTime) { - memset(m_akNormal,0,m_iVQuantity*sizeof(Vector3)); - memset(m_akMean,0,m_iVQuantity*sizeof(Vector3)); + std::fill_n(m_akNormal,m_iVQuantity,Vector3{0,0,0}); + std::fill_n(m_akMean,m_iVQuantity,Vector3{0,0,0}); const int* piIndex = m_aiIndex; int i; diff --git a/src/Mod/Path/libarea/clipper.cpp b/src/Mod/Path/libarea/clipper.cpp index 485edcec76..9513132308 100644 --- a/src/Mod/Path/libarea/clipper.cpp +++ b/src/Mod/Path/libarea/clipper.cpp @@ -64,24 +64,24 @@ static int const Skip = -2; //edge that would otherwise close a path #define NEAR_ZERO(val) (((val) > -TOLERANCE) && ((val) < TOLERANCE)) struct TEdge { - IntPoint Bot; - IntPoint Curr; - IntPoint Top; - IntPoint Delta; - double Dx; - PolyType PolyTyp; - EdgeSide Side; - int WindDelta; //1 or -1 depending on winding direction - int WindCnt; - int WindCnt2; //winding count of the opposite polytype - int OutIdx; - TEdge *Next; - TEdge *Prev; - TEdge *NextInLML; - TEdge *NextInAEL; - TEdge *PrevInAEL; - TEdge *NextInSEL; - TEdge *PrevInSEL; + IntPoint Bot{0,0}; + IntPoint Curr{0,0}; + IntPoint Top{0,0}; + IntPoint Delta{0,0}; + double Dx = 0.0; + PolyType PolyTyp = ptSubject; + EdgeSide Side = esLeft; + int WindDelta = 0; //1 or -1 depending on winding direction + int WindCnt = 0; + int WindCnt2 = 0; //winding count of the opposite polytype + int OutIdx = 0; + TEdge *Next = nullptr; + TEdge *Prev = nullptr; + TEdge *NextInLML = nullptr; + TEdge *NextInAEL = nullptr; + TEdge *PrevInAEL = nullptr; + TEdge *NextInSEL = nullptr; + TEdge *PrevInSEL = nullptr; }; struct IntersectNode { @@ -715,7 +715,6 @@ void DisposeOutPts(OutPt*& pp) inline void InitEdge(TEdge* e, TEdge* eNext, TEdge* ePrev, const IntPoint& Pt) { - std::memset(e, 0, sizeof(TEdge)); e->Next = eNext; e->Prev = ePrev; e->Curr = Pt;