From 9ef2470799ff38610a15e7c43d5e02f38fe1fa67 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 13 Mar 2022 16:32:19 +0100 Subject: [PATCH] PD: Fix several coverity issues: * CID 350558: Uninitialized pointer field * CID 350554: Uninitialized pointer field * CID 350589: Uninitialized pointer field * CID 350608: Uninitialized pointer field * CID 350544: Uncaught exception * CID 350568: Uncaught exception * CID 350603: Uncaught exception * CID 350562: Unchecked dynamic_cast * CID 350591: Unchecked dynamic_cast * CID 350583: Unchecked dynamic_cast * CID 350598: Unchecked dynamic_cast --- .../PartDesign/Gui/TaskExtrudeParameters.cpp | 1 + src/Mod/PartDesign/Gui/TaskPipeParameters.cpp | 29 ++++++++++++++----- src/Mod/PartDesign/Gui/ViewProviderLoft.cpp | 5 +++- src/Mod/PartDesign/Gui/ViewProviderPipe.cpp | 7 +++-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp b/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp index 349033a789..8a14b4e071 100644 --- a/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp @@ -44,6 +44,7 @@ using namespace Gui; TaskExtrudeParameters::TaskExtrudeParameters(ViewProviderSketchBased *SketchBasedView, QWidget *parent, const std::string& pixmapname, const QString& parname) : TaskSketchBasedParameters(SketchBasedView, parent, pixmapname, parname) + , propReferenceAxis(nullptr) , ui(new Ui_TaskPadPocketParameters) { // we need a separate container widget to add all controls to diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 89ffb4e460..5db7ef33ca 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -68,6 +68,7 @@ using namespace Gui; TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj*/, QWidget *parent) : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Pipe parameters")) , ui(new Ui_TaskPipeParameters) + , stateHandler(nullptr) { // we need a separate container widget to add all controls to proxy = new QWidget(this); @@ -151,6 +152,8 @@ TaskPipeParameters::~TaskPipeParameters() static_cast(vp)->highlightReferences(ViewProviderPipe::Profile, false); } } + catch (const Standard_OutOfRange&) { + } catch (const Base::Exception& e) { // getDocument() may raise an exception e.ReportException(); @@ -535,8 +538,9 @@ bool TaskPipeParameters::accept() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newObj*/, QWidget* parent) - : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Section orientation")), - ui(new Ui_TaskPipeOrientation) + : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Section orientation")) + , ui(new Ui_TaskPipeOrientation) + , stateHandler(nullptr) { // we need a separate container widget to add all controls to proxy = new QWidget(this); @@ -599,8 +603,12 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO TaskPipeOrientation::~TaskPipeOrientation() { - if (vp) { - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, false); + try { + if (vp) { + static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, false); + } + } + catch (const Standard_OutOfRange&) { } } @@ -798,8 +806,9 @@ void TaskPipeOrientation::updateUI(int idx) // Task Scaling //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QWidget* parent) - : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Section transformation")), - ui(new Ui_TaskPipeScaling) + : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Section transformation")) + , ui(new Ui_TaskPipeScaling) + , stateHandler(nullptr) { // we need a separate container widget to add all controls to proxy = new QWidget(this); @@ -849,8 +858,12 @@ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QW TaskPipeScaling::~TaskPipeScaling() { - if (vp) { - static_cast(vp)->highlightReferences(ViewProviderPipe::Section, false); + try { + if (vp) { + static_cast(vp)->highlightReferences(ViewProviderPipe::Section, false); + } + } + catch (const Standard_OutOfRange&) { } } diff --git a/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp b/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp index 5e81e4a3d4..9d2e844f5a 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp @@ -149,9 +149,12 @@ void ViewProviderLoft::highlightReferences(ViewProviderLoft::Reference mode, boo void ViewProviderLoft::highlightReferences(Part::Feature* base, const std::vector& elements, bool on) { + if (!base) + return; + PartGui::ViewProviderPart* svp = dynamic_cast( Gui::Application::Instance->getViewProvider(base)); - if (svp == nullptr) + if (!svp) return; std::vector& edgeColors = originalLineColors[base->getID()]; diff --git a/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp b/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp index 25b3a053dd..2d69c21364 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp @@ -145,11 +145,14 @@ void ViewProviderPipe::highlightReferences(ViewProviderPipe::Reference mode, boo } } -void ViewProviderPipe::highlightReferences(Part::Feature* base, const std::vector& edges, bool on) { +void ViewProviderPipe::highlightReferences(Part::Feature* base, const std::vector& edges, bool on) +{ + if (!base) + return; PartGui::ViewProviderPart* svp = dynamic_cast( Gui::Application::Instance->getViewProvider(base)); - if (svp == nullptr) + if (!svp) return; std::vector& edgeColors = originalLineColors[base->getID()];