From 73522c3d10bd91cf586005f691cf1fe2cd2e1b2e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 10 Feb 2018 14:29:49 +0100 Subject: [PATCH] fix scan coverity issues --- src/Mod/Path/PathSimulator/App/VolSim.cpp | 6 +++--- src/Mod/Path/PathSimulator/App/VolSim.h | 10 +++++----- src/Mod/Path/libarea/Curve.cpp | 3 +++ src/Mod/Path/libarea/clipper.cpp | 14 +++++++++++++- src/Mod/Path/libarea/dxf.cpp | 10 +++++----- src/Mod/Path/libarea/kurve/Construction.cpp | 7 ++++++- src/Mod/Path/libarea/kurve/geometry.h | 2 +- src/Mod/Sketcher/App/Sketch.cpp | 9 +++++++-- src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp | 2 +- 9 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/Mod/Path/PathSimulator/App/VolSim.cpp b/src/Mod/Path/PathSimulator/App/VolSim.cpp index 3993c78966..1a95a4de5f 100644 --- a/src/Mod/Path/PathSimulator/App/VolSim.cpp +++ b/src/Mod/Path/PathSimulator/App/VolSim.cpp @@ -676,8 +676,8 @@ void cLineSegment::SetPoints(Point3D & p1, Point3D & p2) void cLineSegment::PointAt(float dist, Point3D & retp) { retp.x = pStart.x + pDir.x * dist; - retp.x = pStart.y + pDir.y * dist; - retp.x = pStart.z + pDir.z * dist; + retp.y = pStart.y + pDir.y * dist; + retp.z = pStart.z + pDir.z * dist; } //************************************************************************************************************ @@ -746,7 +746,7 @@ void cSimTool::InitTool() // pos is 0..1 location along the radius of the tool } } -cVolSim::cVolSim() +cVolSim::cVolSim() : stock(nullptr) { } diff --git a/src/Mod/Path/PathSimulator/App/VolSim.h b/src/Mod/Path/PathSimulator/App/VolSim.h index 261881bbd8..8d448c8743 100644 --- a/src/Mod/Path/PathSimulator/App/VolSim.h +++ b/src/Mod/Path/PathSimulator/App/VolSim.h @@ -36,10 +36,10 @@ #define SIM_WALK_RES 0.6 // step size in pixel units (to make sure all pixels in the path are visited) struct Point3D { - Point3D() {} - Point3D(float x, float y, float z) : x(x), y(y), z(z) {} - Point3D(Base::Vector3d & vec) : x(vec[0]), y(vec[1]), z(vec[2]) {} - Point3D(Base::Placement & pl) : x(pl.getPosition()[0]), y(pl.getPosition()[1]), z(pl.getPosition()[2]) {} + Point3D() : x(0), y(0), z(0), sina(0), cosa(0) {} + Point3D(float x, float y, float z) : x(x), y(y), z(z), sina(0), cosa(0) {} + Point3D(Base::Vector3d & vec) : x(vec[0]), y(vec[1]), z(vec[2]), sina(0), cosa(0) {} + Point3D(Base::Placement & pl) : x(pl.getPosition()[0]), y(pl.getPosition()[1]), z(pl.getPosition()[2]), sina(0), cosa(0) {} inline void set(float px, float py, float pz) { x = px; y = py; z = pz; } inline void Add(Point3D & p) { x += p.x; y += p.y; z += p.z; } inline void Rotate() { float tx = x; x = x * cosa - y * sina; y = tx * sina + y * cosa; } @@ -110,7 +110,7 @@ template class Array2D { public: - Array2D() : data(nullptr) {} + Array2D() : data(nullptr), height(0) {} ~Array2D() { diff --git a/src/Mod/Path/libarea/Curve.cpp b/src/Mod/Path/libarea/Curve.cpp index baa1b02744..0235090688 100644 --- a/src/Mod/Path/libarea/Curve.cpp +++ b/src/Mod/Path/libarea/Curve.cpp @@ -81,6 +81,9 @@ bool CCurve::CheckForArc(const CVertex& prev_vt, std::list& migh } } + if (mid_vt == NULL) + return false; + // create a circle to test Point p0(prev_vt.m_p); Point p1(mid_vt->m_p); diff --git a/src/Mod/Path/libarea/clipper.cpp b/src/Mod/Path/libarea/clipper.cpp index eff46a2b64..e517f8be6c 100644 --- a/src/Mod/Path/libarea/clipper.cpp +++ b/src/Mod/Path/libarea/clipper.cpp @@ -175,7 +175,7 @@ int PolyTree::Total() const // PolyNode methods ... //------------------------------------------------------------------------------ -PolyNode::PolyNode(): Childs(), Parent(0), Index(0), m_IsOpen(false) +PolyNode::PolyNode(): Childs(), Parent(0), Index(0), m_IsOpen(false), m_jointype(jtSquare), m_endtype(etClosedPolygon) { } //------------------------------------------------------------------------------ @@ -876,6 +876,8 @@ ClipperBase::ClipperBase() //constructor { m_CurrentLM = m_MinimaList.begin(); //begin() == end() here m_UseFullRange = false; + m_PreserveCollinear = false; + m_HasOpenPaths = false; } //------------------------------------------------------------------------------ @@ -1347,6 +1349,10 @@ Clipper::Clipper(int initOptions) : ClipperBase() //constructor #ifdef use_xyz m_ZFill = 0; #endif + m_ClipType = ctIntersection; + m_ClipFillType = pftEvenOdd; + m_SubjFillType = pftEvenOdd; + m_UsingPolyTree = false; } //------------------------------------------------------------------------------ @@ -3621,6 +3627,12 @@ ClipperOffset::ClipperOffset(double miterLimit, double arcTolerance) this->MiterLimit = miterLimit; this->ArcTolerance = arcTolerance; m_lowest.X = -1; + m_delta = 0; + m_sinA = 0; + m_sin = 0; + m_cos = 0; + m_miterLim = 0; + m_StepsPerRad = 0; } //------------------------------------------------------------------------------ diff --git a/src/Mod/Path/libarea/dxf.cpp b/src/Mod/Path/libarea/dxf.cpp index adc63ece56..4deb9ff71b 100644 --- a/src/Mod/Path/libarea/dxf.cpp +++ b/src/Mod/Path/libarea/dxf.cpp @@ -164,6 +164,7 @@ void CDxfWrite::WriteEllipse(const double* c, double major_radius, double minor_ CDxfRead::CDxfRead(const char* filepath) { + m_aci = 0; // start the file memset( m_unused_line, '\0', sizeof(m_unused_line) ); m_fail = false; @@ -177,7 +178,6 @@ CDxfRead::CDxfRead(const char* filepath) return; } m_ifs->imbue(std::locale("C")); - } CDxfRead::~CDxfRead() @@ -392,7 +392,7 @@ bool CDxfRead::ReadArc() double start_angle = 0.0;// in degrees double end_angle = 0.0; double radius = 0.0; - double c[3]; // centre + double c[3] = {0,0,0}; // centre while(!((*m_ifs).eof())) { @@ -657,7 +657,7 @@ bool CDxfRead::ReadSpline() bool CDxfRead::ReadCircle() { double radius = 0.0; - double c[3]; // centre + double c[3] = {0,0,0}; // centre while(!((*m_ifs).eof())) { @@ -807,8 +807,8 @@ bool CDxfRead::ReadText() bool CDxfRead::ReadEllipse() { - double c[3]; // centre - double m[3]; //major axis point + double c[3]={0,0,0}; // centre + double m[3]={1,0,0}; //major axis point double ratio=0; //ratio of major to minor axis double start=0; //start of arc double end=0; // end of arc diff --git a/src/Mod/Path/libarea/kurve/Construction.cpp b/src/Mod/Path/libarea/kurve/Construction.cpp index f8bba29c57..793d4643f5 100644 --- a/src/Mod/Path/libarea/kurve/Construction.cpp +++ b/src/Mod/Path/libarea/kurve/Construction.cpp @@ -141,7 +141,7 @@ namespace geoff_geometry { Point::Point(const Vector2d& v) { - x = v.getx(); y = v.gety(); + x = v.getx(); y = v.gety(); ok = true; } Point3d::Point3d(const Vector3d& v) { @@ -369,6 +369,9 @@ namespace geoff_geometry { pc = pc0; radius = p.Dist(pc0); } + else { + radius = 0; + } } Circle::Circle( const Span& sp){ @@ -779,6 +782,7 @@ namespace geoff_geometry { // constructor plane from point & vector normal = v; if(normalise == true) normal.normalise(); + ok = (normal != NULL_VECTOR); d = -(normal * Vector3d(p0)); } @@ -787,6 +791,7 @@ namespace geoff_geometry { double mag = normal.normalise(); ok = (normal != NULL_VECTOR); if(ok) d = dist / mag; + else d = 0; } double Plane::Dist(const Point3d& p)const{ diff --git a/src/Mod/Path/libarea/kurve/geometry.h b/src/Mod/Path/libarea/kurve/geometry.h index aafa757215..4b435cce23 100644 --- a/src/Mod/Path/libarea/kurve/geometry.h +++ b/src/Mod/Path/libarea/kurve/geometry.h @@ -210,7 +210,7 @@ inline bool FNEZ(double a, double tolerance = TIGHT_TOLERANCE) {return fabs(a) > double y; // y value // constructors etc... - inline Point(){ ok=false;}; // Point p1 + inline Point(){x=0; y=0; ok=false;} // Point p1 inline Point( double xord, double yord, bool okay = true) { // Point p1(10,30); x = xord; y = yord; ok = okay;} inline Point( const Point& p ) { // copy constructor Point p1(p2); diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index b96152eede..b58faf8031 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -67,8 +67,13 @@ using namespace Part; TYPESYSTEM_SOURCE(Sketcher::Sketch, Base::Persistence) Sketch::Sketch() -: SolveTime(0), RecalculateInitialSolutionWhileMovingPoint(false), GCSsys(), ConstraintsCounter(0), isInitMove(false), isFine(true), -defaultSolver(GCS::DogLeg),defaultSolverRedundant(GCS::DogLeg),debugMode(GCS::Minimal) + : SolveTime(0) + , RecalculateInitialSolutionWhileMovingPoint(false) + , GCSsys(), ConstraintsCounter(0) + , isInitMove(false), isFine(true), moveStep(0) + , defaultSolver(GCS::DogLeg) + , defaultSolverRedundant(GCS::DogLeg) + , debugMode(GCS::Minimal) { } diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index c5697c2b03..b587aa599a 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -806,7 +806,7 @@ void TaskSketcherConstrains::slotConstraintsChanged(void) /* Update the states */ ui->listWidgetConstraints->blockSignals(true); for (int i = 0; i < ui->listWidgetConstraints->count(); ++i) { - ConstraintItem * it = dynamic_cast(ui->listWidgetConstraints->item(i)); + ConstraintItem * it = static_cast(ui->listWidgetConstraints->item(i)); it->updateVirtualSpaceStatus(); } ui->listWidgetConstraints->blockSignals(false);