From e8b36592c0d1f55a2cb7ef8f0b927c8f84dfaaee Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 21 Aug 2016 18:46:40 +0200 Subject: [PATCH] fix Coverity issues --- src/Mod/Part/App/Attacher.cpp | 3 -- src/Mod/Part/App/FeatureExtrusion.cpp | 2 +- src/Mod/Part/App/GeometryCurvePyImp.cpp | 3 -- src/Mod/Part/App/TopoShape.cpp | 4 +-- src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 3 -- src/Mod/Part/App/TopoShapeFacePyImp.cpp | 5 ++-- src/Mod/Part/Gui/DlgPrimitives.cpp | 1 + src/Mod/Part/Gui/DlgRevolution.cpp | 1 + src/Mod/Part/Gui/TaskDimension.cpp | 6 ++-- src/Mod/Part/Gui/ViewProviderCompound.cpp | 5 +++- src/Mod/Part/Gui/ViewProviderCurveNet.h | 4 +++ src/Mod/Part/Gui/ViewProviderMirror.cpp | 4 +-- src/Mod/PartDesign/App/FeatureLoft.cpp | 2 -- .../PartDesign/App/FeatureMultiTransform.cpp | 6 ++-- src/Mod/PartDesign/App/FeaturePipe.cpp | 4 +-- src/Mod/PartDesign/App/FeatureScaled.cpp | 6 ++-- src/Mod/PartDesign/Gui/Command.cpp | 30 +++++++++---------- src/Mod/PartDesign/Gui/CommandBody.cpp | 1 - .../PartDesign/Gui/TaskBooleanParameters.cpp | 5 ++-- .../PartDesign/Gui/TaskDressUpParameters.cpp | 8 +++-- 20 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index 3ad563179..9ce107f5c 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -733,9 +733,6 @@ GProp_GProps AttachEngine::getInertialPropsOfShape(const std::vectorGetMessageString()); return 0; } - - PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); - return 0; } PyObject* GeometryCurvePy::intersect2d(PyObject *args) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 69e5020fa..8b175ccfb 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -2313,11 +2313,11 @@ struct MeshVertex Standard_Integer i; MeshVertex(Standard_Real X, Standard_Real Y, Standard_Real Z) - : x(X),y(Y),z(Z) + : x(X),y(Y),z(Z),i(0) { } MeshVertex(const gp_Pnt& p) - : x(p.X()),y(p.Y()),z(p.Z()) + : x(p.X()),y(p.Y()),z(p.Z()),i(0) { } diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index bf7cf876e..857021f19 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -624,9 +624,6 @@ PyObject* TopoShapeEdgePy::split(PyObject *args) PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); return 0; } - - PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); - return 0; } PyObject* TopoShapeEdgePy::isSeam(PyObject *args) diff --git a/src/Mod/Part/App/TopoShapeFacePyImp.cpp b/src/Mod/Part/App/TopoShapeFacePyImp.cpp index 580863690..d5185917d 100644 --- a/src/Mod/Part/App/TopoShapeFacePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeFacePyImp.cpp @@ -683,10 +683,9 @@ Py::Object TopoShapeFacePy::getOuterWire(void) const TopoDS_Wire clWire = ShapeAnalysis::OuterWire(clFace); return Py::Object(new TopoShapeWirePy(new TopoShape(clWire)),true); } - else + else { throw Py::Exception("Internal error, TopoDS_Shape is not a face!"); - - return Py::Object(); + } } Py::Object TopoShapeFacePy::getMass(void) const diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index de2c03012..cd2133d79 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -683,6 +683,7 @@ void DlgPrimitives::createPrimitive(const QString& placement) Location::Location(QWidget* parent) { + mode = 0; ui.setupUi(this); } diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 16cfe1de2..4e424bd07 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -65,6 +65,7 @@ public: EdgeSelection() : Gui::SelectionFilterGate((Gui::SelectionFilter*)0) { + canSelect = false; } bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName) { diff --git a/src/Mod/Part/Gui/TaskDimension.cpp b/src/Mod/Part/Gui/TaskDimension.cpp index b7f2d9886..05377cb11 100644 --- a/src/Mod/Part/Gui/TaskDimension.cpp +++ b/src/Mod/Part/Gui/TaskDimension.cpp @@ -1232,8 +1232,10 @@ void PartGui::ArcEngine::defaultValues() SO_ENGINE_OUTPUT(pointCount, SoSFInt32, setValue(2)); } -PartGui::SteppedSelection::SteppedSelection(const uint& buttonCountIn, QWidget* parent): - QWidget(parent) +PartGui::SteppedSelection::SteppedSelection(const uint& buttonCountIn, QWidget* parent) + : QWidget(parent) + , stepActive(0) + , stepDone(0) { if (buttonCountIn < 1) return; diff --git a/src/Mod/Part/Gui/ViewProviderCompound.cpp b/src/Mod/Part/Gui/ViewProviderCompound.cpp index a9f42b5ce..b116b17f3 100644 --- a/src/Mod/Part/Gui/ViewProviderCompound.cpp +++ b/src/Mod/Part/Gui/ViewProviderCompound.cpp @@ -69,7 +69,7 @@ void ViewProviderCompound::updateData(const App::Property* prop) if (prop->getTypeId() == Part::PropertyShapeHistory::getClassTypeId()) { const std::vector& hist = static_cast (prop)->getValues(); - Part::Compound* objComp = dynamic_cast(getObject()); + Part::Compound* objComp = static_cast(getObject()); std::vector sources = objComp->Links.getValues(); if (hist.size() != sources.size()) return; @@ -85,6 +85,9 @@ void ViewProviderCompound::updateData(const App::Property* prop) int index=0; for (std::vector::iterator it = sources.begin(); it != sources.end(); ++it, ++index) { Part::Feature* objBase = dynamic_cast(*it); + if (!objBase) + continue; + const TopoDS_Shape& baseShape = objBase->Shape.getValue(); TopTools_IndexedMapOfShape baseMap; diff --git a/src/Mod/Part/Gui/ViewProviderCurveNet.h b/src/Mod/Part/Gui/ViewProviderCurveNet.h index 0523ed061..87a644938 100644 --- a/src/Mod/Part/Gui/ViewProviderCurveNet.h +++ b/src/Mod/Part/Gui/ViewProviderCurveNet.h @@ -68,6 +68,10 @@ protected: struct Node { Gui::SoFCSelection *pcHighlight; SoTransform *pcTransform; + Node() { + pcHighlight = 0; + pcTransform = 0; + } }; std::list NodeList; diff --git a/src/Mod/Part/Gui/ViewProviderMirror.cpp b/src/Mod/Part/Gui/ViewProviderMirror.cpp index 485c18441..2307a12ae 100644 --- a/src/Mod/Part/Gui/ViewProviderMirror.cpp +++ b/src/Mod/Part/Gui/ViewProviderMirror.cpp @@ -239,7 +239,7 @@ void ViewProviderFillet::updateData(const App::Property* prop) return; Part::Fillet* objFill = dynamic_cast(getObject()); Part::Feature* objBase = dynamic_cast(objFill->Base.getValue()); - if (objBase) { + if (objFill && objBase) { const TopoDS_Shape& baseShape = objBase->Shape.getValue(); const TopoDS_Shape& fillShape = objFill->Shape.getValue(); @@ -342,7 +342,7 @@ void ViewProviderChamfer::updateData(const App::Property* prop) return; Part::Chamfer* objCham = dynamic_cast(getObject()); Part::Feature* objBase = dynamic_cast(objCham->Base.getValue()); - if (objBase) { + if (objCham && objBase) { const TopoDS_Shape& baseShape = objBase->Shape.getValue(); const TopoDS_Shape& chamShape = objCham->Shape.getValue(); diff --git a/src/Mod/PartDesign/App/FeatureLoft.cpp b/src/Mod/PartDesign/App/FeatureLoft.cpp index 277060dfa..09b1499ca 100644 --- a/src/Mod/PartDesign/App/FeatureLoft.cpp +++ b/src/Mod/PartDesign/App/FeatureLoft.cpp @@ -212,8 +212,6 @@ App::DocumentObjectExecReturn *Loft::execute(void) } return App::DocumentObject::StdReturn; - - return ProfileBased::execute(); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); diff --git a/src/Mod/PartDesign/App/FeatureMultiTransform.cpp b/src/Mod/PartDesign/App/FeatureMultiTransform.cpp index 59a2eaa79..738368bfd 100644 --- a/src/Mod/PartDesign/App/FeatureMultiTransform.cpp +++ b/src/Mod/PartDesign/App/FeatureMultiTransform.cpp @@ -80,9 +80,9 @@ const std::list MultiTransform::getTransformations(const std::vectorgetTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) { PartDesign::FeatureAddSub* addFeature = static_cast(originalFeature); - if(addFeature->getAddSubType() == FeatureAddSub::Additive) - original = addFeature->AddSubShape.getShape().getShape(); - else + //if (addFeature->getAddSubType() == FeatureAddSub::Additive) + // original = addFeature->AddSubShape.getShape().getShape(); + //else original = addFeature->AddSubShape.getShape().getShape(); } diff --git a/src/Mod/PartDesign/App/FeaturePipe.cpp b/src/Mod/PartDesign/App/FeaturePipe.cpp index 224d5c054..c5c5dfd44 100644 --- a/src/Mod/PartDesign/App/FeaturePipe.cpp +++ b/src/Mod/PartDesign/App/FeaturePipe.cpp @@ -317,10 +317,8 @@ App::DocumentObjectExecReturn *Pipe::execute(void) boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); } - + return App::DocumentObject::StdReturn; - - return ProfileBased::execute(); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); diff --git a/src/Mod/PartDesign/App/FeatureScaled.cpp b/src/Mod/PartDesign/App/FeatureScaled.cpp index 171702a75..69abc8889 100644 --- a/src/Mod/PartDesign/App/FeatureScaled.cpp +++ b/src/Mod/PartDesign/App/FeatureScaled.cpp @@ -74,9 +74,9 @@ const std::list Scaled::getTransformations(const std::vectorgetTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) { PartDesign::FeatureAddSub* Feature = static_cast(originalFeature); - if(Feature->getAddSubType() == FeatureAddSub::Additive) - original = Feature->AddSubShape.getShape().getShape(); - else + //if(Feature->getAddSubType() == FeatureAddSub::Additive) + // original = Feature->AddSubShape.getShape().getShape(); + //else original = Feature->AddSubShape.getShape().getShape(); } diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 54614cce7..dc11856cc 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -726,29 +726,28 @@ void prepareProfileBased(Gui::Command* cmd, const std::string& which, //if a profie is selected we can make our life easy and fast auto selection = cmd->getSelection().getSelectionEx(); - if(!selection.empty() && selection.front().hasSubNames()) { - + if (!selection.empty() && selection.front().hasSubNames()) { base_worker(selection.front().getObject(), selection.front().getSubNames().front()); return; } - + //no face profile was selected, do he extended sketch logic - + bool bNoSketchWasSelected = false; // Get a valid sketch from the user // First check selections std::vector sketches = cmd->getSelection().getObjectsOfType(Part::Part2DObject::getClassTypeId()); - if (sketches.size() == 0) {//no sketches were selected. Let user pick an object from valid ones available in document + if (sketches.empty()) {//no sketches were selected. Let user pick an object from valid ones available in document sketches = cmd->getDocument()->getObjectsOfType(Part::Part2DObject::getClassTypeId()); bNoSketchWasSelected = true; } - if(sketches.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No sketch to work on"), - QObject::tr("No sketch is available in the document")); - return; + if (sketches.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No sketch to work on"), + QObject::tr("No sketch is available in the document")); + return; } - + std::vector status; std::vector::iterator firstFreeSketch; int freeSketches = validateSketches(sketches, status, firstFreeSketch); @@ -778,7 +777,7 @@ void prepareProfileBased(Gui::Command* cmd, const std::string& which, // TODO Clean this up (2015-10-20, Fat-Zer) auto* pcActiveBody = PartDesignGui::getBody(false); - if(pcActiveBody && !bNoSketchWasSelected && ext) { + if (pcActiveBody && !bNoSketchWasSelected && ext) { auto* pcActivePart = PartDesignGui::getPartFor(pcActiveBody, false); @@ -805,7 +804,7 @@ void prepareProfileBased(Gui::Command* cmd, const std::string& which, // Show sketch choose dialog and let user pick sketch if no sketch was selected and no free one available or // multiple free ones are available - if ( bNoSketchWasSelected && (freeSketches != 1) ) { + if (bNoSketchWasSelected && (freeSketches != 1) ) { Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); PartDesignGui::TaskDlgFeaturePick *pickDlg = qobject_cast(dlg); @@ -827,21 +826,20 @@ void prepareProfileBased(Gui::Command* cmd, const std::string& which, Gui::Selection().clearSelection(); pickDlg = new PartDesignGui::TaskDlgFeaturePick(sketches, status, accepter, sketch_worker); - if(!bNoSketchWasSelected && ext) + if (!bNoSketchWasSelected && ext) pickDlg->showExternal(true); Gui::Control().showDialog(pickDlg); } else { std::vector theSketch; - if(!bNoSketchWasSelected) + if (!bNoSketchWasSelected) theSketch.push_back(sketches[0]); else theSketch.push_back(*firstFreeSketch); - + sketch_worker(theSketch); } - } void finishProfileBased(const Gui::Command* cmd, const Part::Feature* sketch, const std::string& FeatName) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index fe28d6c7b..59b897c63 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -666,7 +666,6 @@ void CmdPartDesignMoveFeature::activated(int iMsg) bool CmdPartDesignMoveFeature::isActive(void) { return hasActiveDocument () && !PartDesignGui::isLegacyWorkflow ( getDocument () ); - return hasActiveDocument (); } DEF_STD_CMD_A(CmdPartDesignMoveFeatureInTree); diff --git a/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp b/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp index 11ccadce4..83daec0c6 100644 --- a/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp @@ -177,10 +177,9 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskBooleanParameters::onButtonBodyAdd(bool checked) { if (checked) { - Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (doc != NULL) - BooleanView->hide(); PartDesign::Boolean* pcBoolean = static_cast(BooleanView->getObject()); + Gui::Document* doc = BooleanView->getDocument(); + BooleanView->hide(); if (pcBoolean->Bodies.getValues().empty() && pcBoolean->BaseFeature.getValue()) doc->setHide(pcBoolean->BaseFeature.getValue()->getNameInDocument()); selectionMode = bodyAdd; diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index a36fde5b5..ece39a1e1 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -51,8 +51,11 @@ TaskDressUpParameters::TaskDressUpParameters(ViewProviderDressUp *DressUpView, b : TaskBox(Gui::BitmapFactory().pixmap((std::string("PartDesign_") + DressUpView->featureName()).c_str()), QString::fromLatin1((DressUpView->featureName() + " parameters").c_str()), true, - parent), - DressUpView(DressUpView), allowFaces(selectFaces), allowEdges(selectEdges) + parent) + , proxy(0) + , DressUpView(DressUpView) + , allowFaces(selectFaces) + , allowEdges(selectEdges) { selectionMode = none; } @@ -192,6 +195,7 @@ void TaskDressUpParameters::exitSelectionMode() TaskDlgDressUpParameters::TaskDlgDressUpParameters(ViewProviderDressUp *DressUpView) : TaskDlgFeatureParameters(DressUpView) + , parameter(0) { assert(DressUpView); }