From b480a207c0489577660283cf23f03fadc133146f Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 20 Jul 2020 13:58:15 +0200 Subject: [PATCH] Coverity: Uncaught exception --- src/Gui/DocumentObserver.cpp | 23 ++++---- src/Gui/Selection.cpp | 48 ++++++++++++----- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 2 +- src/Mod/PartDesign/Gui/TaskPipeParameters.cpp | 54 +++++++++++-------- 4 files changed, 81 insertions(+), 46 deletions(-) diff --git a/src/Gui/DocumentObserver.cpp b/src/Gui/DocumentObserver.cpp index e59a84b13f..a4e519a5b8 100644 --- a/src/Gui/DocumentObserver.cpp +++ b/src/Gui/DocumentObserver.cpp @@ -251,15 +251,20 @@ Gui::Document* DocumentWeakPtrT::operator->() noexcept class ViewProviderWeakPtrT::Private { public: Private(ViewProviderDocumentObject* obj) : object(obj), indocument(false) { - if (obj) { - indocument = true; - Gui::Document* doc = obj->getDocument(); - connectApplicationDeletedDocument = doc->signalDeleteDocument.connect(boost::bind - (&Private::deletedDocument, this, bp::_1)); - connectDocumentCreatedObject = doc->signalNewObject.connect(boost::bind - (&Private::createdObject, this, bp::_1)); - connectDocumentDeletedObject = doc->signalDeletedObject.connect(boost::bind - (&Private::deletedObject, this, bp::_1)); + try { + if (obj) { + Gui::Document* doc = obj->getDocument(); + indocument = true; + connectApplicationDeletedDocument = doc->signalDeleteDocument.connect(boost::bind + (&Private::deletedDocument, this, bp::_1)); + connectDocumentCreatedObject = doc->signalNewObject.connect(boost::bind + (&Private::createdObject, this, bp::_1)); + connectDocumentDeletedObject = doc->signalDeletedObject.connect(boost::bind + (&Private::deletedObject, this, bp::_1)); + } + } + catch (const Base::RuntimeError&) { + // getDocument() may raise an exception } } void deletedDocument(const Gui::Document& doc) { diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 515a3c6328..39f28021b6 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -131,14 +131,16 @@ bool SelectionObserver::isConnectionAttached() const void SelectionObserver::attachSelection() { if (!connectSelection.connected()) { - auto &signal = resolve>1?Selection().signalSelectionChanged3:( - resolve?Selection().signalSelectionChanged2: - Selection().signalSelectionChanged); + auto &signal = resolve > 1 ? Selection().signalSelectionChanged3 : + resolve ? Selection().signalSelectionChanged2 : + Selection().signalSelectionChanged ; connectSelection = signal.connect(boost::bind (&SelectionObserver::_onSelectionChanged, this, bp::_1)); - if(filterDocName.size()) + + if (filterDocName.size()) { Selection().addSelectionGate( new SelectionGateFilterExternal(filterDocName.c_str(),filterObjName.c_str())); + } } } @@ -596,7 +598,13 @@ void SelectionSingleton::notify(SelectionChanges &&Chng) { } if(notify) { Notify(msg); - signalSelectionChanged(msg); + try { + signalSelectionChanged(msg); + } + catch (const boost::exception&) { + // reported by code analyzers + Base::Console().Warning("notify: Unexpected boost exception\n"); + } } NotificationQueue.pop_front(); } @@ -732,16 +740,28 @@ void SelectionSingleton::slotSelectionChanged(const SelectionChanges& msg) { newElementName.size()?newElementName.c_str():oldElementName.c_str(), pObject->getTypeId().getName(), msg.x,msg.y,msg.z); - msg2.pOriginalMsg = &msg; - signalSelectionChanged3(msg2); + try { + msg2.pOriginalMsg = &msg; + signalSelectionChanged3(msg2); - msg2.Object.setSubName(oldElementName.c_str()); - msg2.pSubName = msg2.Object.getSubName().c_str(); - signalSelectionChanged2(msg2); - - }else { - signalSelectionChanged3(msg); - signalSelectionChanged2(msg); + msg2.Object.setSubName(oldElementName.c_str()); + msg2.pSubName = msg2.Object.getSubName().c_str(); + signalSelectionChanged2(msg2); + } + catch (const boost::exception&) { + // reported by code analyzers + Base::Console().Warning("slotSelectionChanged: Unexpected boost exception\n"); + } + } + else { + try { + signalSelectionChanged3(msg); + signalSelectionChanged2(msg); + } + catch (const boost::exception&) { + // reported by code analyzers + Base::Console().Warning("slotSelectionChanged: Unexpected boost exception\n"); + } } } diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index bff431b6b6..cbfc57d023 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -593,7 +593,7 @@ void PartGui::DlgProjectionOnSurface::higlight_object(Part::Feature* iCurrentObj { if (!iCurrentObject) return; auto partenShape = iCurrentObject->Shape.getShape().getShape(); - auto subShape = iCurrentObject->Shape.getShape().getSubShape(iShapeName.c_str()); + auto subShape = iCurrentObject->Shape.getShape().getSubShape(iShapeName.c_str(), true); TopoDS_Shape currentShape = subShape; if (subShape.IsNull()) currentShape = partenShape; diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index ab4fa5b03a..1f939ca24a 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -120,19 +120,24 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj TaskPipeParameters::~TaskPipeParameters() { - if (vp) { - PartDesign::Pipe* pipe = static_cast(vp->getObject()); - Gui::Document* doc = vp->getDocument(); + try { + if (vp) { + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + Gui::Document* doc = vp->getDocument(); - //make sure the user sees all important things: the - //spine/auxiliary spine he already selected - if (pipe->Spine.getValue()) { - auto* svp = doc->getViewProvider(pipe->Spine.getValue()); - svp->setVisible(spineShow); - spineShow = false; + //make sure the user sees all important things: the + //spine/auxiliary spine he already selected + if (pipe->Spine.getValue()) { + auto* svp = doc->getViewProvider(pipe->Spine.getValue()); + svp->setVisible(spineShow); + spineShow = false; + } + + static_cast(vp)->highlightReferences(false, false); } - - static_cast(vp)->highlightReferences(false, false); + } + catch (const Base::RuntimeError&) { + // getDocument() may raise an exception } delete ui; @@ -420,19 +425,24 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO TaskPipeOrientation::~TaskPipeOrientation() { - if (vp) { - PartDesign::Pipe* pipe = static_cast(vp->getObject()); - Gui::Document* doc = vp->getDocument(); + try { + if (vp) { + PartDesign::Pipe* pipe = static_cast(vp->getObject()); + Gui::Document* doc = vp->getDocument(); - //make sure the user sees al important things: the base feature to select edges and the - //spine/auxiliary spine he already selected - if (pipe->AuxillerySpine.getValue()) { - auto* svp = doc->getViewProvider(pipe->AuxillerySpine.getValue()); - svp->setVisible(auxSpineShow); - auxSpineShow = false; + //make sure the user sees al important things: the base feature to select edges and the + //spine/auxiliary spine he already selected + if (pipe->AuxillerySpine.getValue()) { + auto* svp = doc->getViewProvider(pipe->AuxillerySpine.getValue()); + svp->setVisible(auxSpineShow); + auxSpineShow = false; + } + + static_cast(vp)->highlightReferences(false, true); } - - static_cast(vp)->highlightReferences(false, true); + } + catch (const Base::RuntimeError&) { + // getDocument() may raise an exception } }