From ca343c43ab5260d3783c47bfef7685cb26ba6154 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 11 Apr 2017 12:45:02 +0200 Subject: [PATCH] fix scan coverity issues: unchecked dynamic_cast --- src/Mod/Sketcher/App/Sketch.cpp | 14 +++++++------- src/Mod/Sketcher/App/SketchObject.cpp | 6 +++--- src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 8 ++++---- src/Mod/TechDraw/Gui/CommandDecorate.cpp | 3 +++ src/Mod/TechDraw/Gui/QGIViewImage.cpp | 2 ++ 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index f4da741516..1bafa53c67 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -231,7 +231,7 @@ int Sketch::addGeometry(const Part::Geometry *geo, bool fixed) // create the definition struct for that geom return addArcOfHyperbola(*aoh, fixed); } else if (geo->getTypeId() == GeomArcOfParabola::getClassTypeId()) { // add an arc of parabola - const GeomArcOfParabola *aop = dynamic_cast(geo); + const GeomArcOfParabola *aop = static_cast(geo); // create the definition struct for that geom return addArcOfParabola(*aop, fixed); } else if (geo->getTypeId() == GeomBSplineCurve::getClassTypeId()) { // add a bspline @@ -937,13 +937,13 @@ Py::Tuple Sketch::getPyGeometry(void) const GeomArcOfEllipse *ellipse = static_cast(it->geo->clone()); tuple[i] = Py::asObject(new ArcOfEllipsePy(ellipse)); } else if (it->type == ArcOfHyperbola) { - GeomArcOfHyperbola *aoh = dynamic_cast(it->geo->clone()); + GeomArcOfHyperbola *aoh = static_cast(it->geo->clone()); tuple[i] = Py::asObject(new ArcOfHyperbolaPy(aoh)); } else if (it->type == ArcOfParabola) { - GeomArcOfParabola *aop = dynamic_cast(it->geo->clone()); + GeomArcOfParabola *aop = static_cast(it->geo->clone()); tuple[i] = Py::asObject(new ArcOfParabolaPy(aop)); } else if (it->type == BSpline) { - GeomBSplineCurve *bsp = dynamic_cast(it->geo->clone()); + GeomBSplineCurve *bsp = static_cast(it->geo->clone()); tuple[i] = Py::asObject(new BSplineCurvePy(bsp)); } else { // not implemented type in the sketch! @@ -2641,7 +2641,7 @@ bool Sketch::updateGeometry() } else if (it->type == ArcOfHyperbola) { GCS::ArcOfHyperbola &myArc = ArcsOfHyperbola[it->index]; - GeomArcOfHyperbola *aoh = dynamic_cast(it->geo); + GeomArcOfHyperbola *aoh = static_cast(it->geo); Base::Vector3d center = Vector3d(*Points[it->midPointId].x, *Points[it->midPointId].y, 0.0); Base::Vector3d f1 = Vector3d(*myArc.focus1.x, *myArc.focus1.y, 0.0); @@ -2663,7 +2663,7 @@ bool Sketch::updateGeometry() } else if (it->type == ArcOfParabola) { GCS::ArcOfParabola &myArc = ArcsOfParabola[it->index]; - GeomArcOfParabola *aop = dynamic_cast(it->geo); + GeomArcOfParabola *aop = static_cast(it->geo); Base::Vector3d vertex = Vector3d(*Points[it->midPointId].x, *Points[it->midPointId].y, 0.0); Base::Vector3d f1 = Vector3d(*myArc.focus1.x, *myArc.focus1.y, 0.0); @@ -2677,7 +2677,7 @@ bool Sketch::updateGeometry() } else if (it->type == BSpline) { GCS::BSpline &mybsp = BSplines[it->index]; - GeomBSplineCurve *bsp = dynamic_cast(it->geo); + GeomBSplineCurve *bsp = static_cast(it->geo); std::vector poles; std::vector weights; diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index b953884ce1..34b929bde4 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -520,7 +520,7 @@ Base::Vector3d SketchObject::getPoint(int GeoId, PointPos PosId) const else if (PosId == mid) return aoh->getCenter(); } else if (geo->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola *aop = dynamic_cast(geo); + const Part::GeomArcOfParabola *aop = static_cast(geo); if (PosId == start) return aop->getStartPoint(); else if (PosId == end) @@ -1050,7 +1050,7 @@ int SketchObject::fillet(int GeoId1, int GeoId2, } dist1.ProjectToLine(arc->getStartPoint(/*emulateCCW=*/true)-intersection, dir1); dist2.ProjectToLine(arc->getStartPoint(/*emulateCCW=*/true)-intersection, dir2); - Part::Geometry *newgeo = dynamic_cast(arc); + Part::Geometry *newgeo = arc; filletId = addGeometry(newgeo); if (filletId < 0) { delete arc; @@ -1937,7 +1937,7 @@ int SketchObject::trim(int GeoId, const Base::Vector3d& point) } else { // trim arc end delConstraintOnPoint(GeoId, end, false); - Part::GeomArcOfHyperbola *aoe1 = dynamic_cast(geomlist[GeoId]); + Part::GeomArcOfHyperbola *aoe1 = static_cast(geomlist[GeoId]); aoe1->setRange(startAngle, startAngle + theta1, /*emulateCCW=*/true); Sketcher::Constraint *newConstr = new Sketcher::Constraint(); newConstr->Type = constrType; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp index 885d7736fa..4e9bdb7e0c 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp @@ -228,7 +228,7 @@ void SketcherValidation::on_findButton_clicked() vertexIds.push_back(id); } else if (g->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola *segm = dynamic_cast(g); + const Part::GeomArcOfParabola *segm = static_cast(g); VertexIds id; id.GeoId = (int)i; id.PosId = Sketcher::start; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 5ce9e3d814..38795fe221 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2293,7 +2293,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } else if ((*it)->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { // Check if arc lies inside box selection - const Part::GeomArcOfParabola *aop = dynamic_cast(*it); + const Part::GeomArcOfParabola *aop = static_cast(*it); pnt0 = aop->getStartPoint(); pnt1 = aop->getEndPoint(); @@ -4112,7 +4112,7 @@ Restart: angle1plus = (startangle + endangle)/2; midpos1 = aoe->getCenter(); } else if (geo1->getTypeId() == Part::GeomArcOfHyperbola::getClassTypeId()) { - const Part::GeomArcOfHyperbola *aoh = dynamic_cast(geo1); + const Part::GeomArcOfHyperbola *aoh = static_cast(geo1); r1a = aoh->getMajorRadius(); r1b = aoh->getMinorRadius(); double startangle, endangle; @@ -4122,7 +4122,7 @@ Restart: angle1plus = (startangle + endangle)/2; midpos1 = aoh->getCenter(); } else if (geo1->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola *aop = dynamic_cast(geo1); + const Part::GeomArcOfParabola *aop = static_cast(geo1); r1a = aop->getFocal(); double startangle, endangle; aop->getRange(startangle, endangle, /*emulateCCW=*/true); @@ -4174,7 +4174,7 @@ Restart: angle2plus = (startangle + endangle)/2; midpos2 = aoh->getCenter(); } else if (geo2->getTypeId() == Part::GeomArcOfParabola::getClassTypeId()) { - const Part::GeomArcOfParabola *aop = dynamic_cast(geo2); + const Part::GeomArcOfParabola *aop = static_cast(geo2); r2a = aop->getFocal(); double startangle, endangle; aop->getRange(startangle, endangle, /*emulateCCW=*/true); diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 072ec006de..4f06f17dd3 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -175,6 +175,9 @@ void CmdTechDrawNewGeomHatch::activated(int iMsg) geomhatch->Source.setValue(objFeat, subNames); Gui::ViewProvider* vp = Gui::Application::Instance->getDocument(getDocument())->getViewProvider(geomhatch); TechDrawGui::ViewProviderGeomHatch* hvp = dynamic_cast(vp); + if( hvp == nullptr ) { + return; + } // if (!hvp) { // dialog to fill in hatch values diff --git a/src/Mod/TechDraw/Gui/QGIViewImage.cpp b/src/Mod/TechDraw/Gui/QGIViewImage.cpp index a626a64205..0e5e5da374 100644 --- a/src/Mod/TechDraw/Gui/QGIViewImage.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewImage.cpp @@ -115,6 +115,8 @@ void QGIViewImage::draw() } auto viewImage( dynamic_cast(getViewObject()) ); + if (!viewImage) + return; QRectF newRect(0.0,0.0,Rez::guiX(viewImage->Width.getValue()),Rez::guiX(viewImage->Height.getValue())); double pad = Rez::guiX(1.0); m_cliparea->setRect(newRect.adjusted(-pad,-pad,pad,pad));