From ab525189bf5c88cafddc7777cce7185c32c0d898 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 16 Aug 2016 16:34:51 +0200 Subject: [PATCH] Coverity issues: 129097 129098 129099 129101 129102 129132 129134 129203 --- src/Gui/CommandView.cpp | 14 +++++++------- src/Gui/DlgActionsImp.cpp | 2 ++ src/Gui/Document.cpp | 9 +++++++-- src/Gui/GuiApplication.cpp | 2 +- src/Gui/View3DInventorViewer.cpp | 3 ++- src/Gui/WidgetFactory.cpp | 7 +++++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 80f252b44..29140ccf8 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -812,13 +812,13 @@ void StdCmdToggleSelectability::activated(int iMsg) for (std::vector::const_iterator ft=sel.begin();ft!=sel.end();++ft) { ViewProvider *pr = pcDoc->getViewProviderByName((*ft)->getNameInDocument()); - if(pr->isDerivedFrom(ViewProviderGeometryObject::getClassTypeId())){ - if (dynamic_cast(pr)->Selectable.getValue()) - doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Selectable=False" - , (*it)->getName(), (*ft)->getNameInDocument()); - else - doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Selectable=True" - , (*it)->getName(), (*ft)->getNameInDocument()); + if (pr->isDerivedFrom(ViewProviderGeometryObject::getClassTypeId())){ + if (static_cast(pr)->Selectable.getValue()) + doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Selectable=False" + , (*it)->getName(), (*ft)->getNameInDocument()); + else + doCommand(Gui,"Gui.getDocument(\"%s\").getObject(\"%s\").Selectable=True" + , (*it)->getName(), (*ft)->getNameInDocument()); } } } diff --git a/src/Gui/DlgActionsImp.cpp b/src/Gui/DlgActionsImp.cpp index 4f200ec89..372334980 100644 --- a/src/Gui/DlgActionsImp.cpp +++ b/src/Gui/DlgActionsImp.cpp @@ -306,6 +306,8 @@ void DlgCustomActionsImp::on_buttonReplaceAction_clicked() CommandManager& rclMan = Application::Instance->commandManager(); Command* pCmd = rclMan.getCommandByName(actionName.constData()); MacroCommand* macro = dynamic_cast(pCmd); + if (!macro) + return; if (!actionWhatsThis->text().isEmpty()) macro->setWhatsThis(actionWhatsThis->text().toUtf8()); diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index de05933ef..a7fe5d9f2 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -219,8 +219,13 @@ bool Document::setEdit(Gui::ViewProvider* p, int ModNum) { if (d->_editViewProvider) resetEdit(); + // is it really a ViewProvider of this document? - if (d->_ViewProviderMap.find(dynamic_cast(p)->getObject()) == d->_ViewProviderMap.end()) + ViewProviderDocumentObject* vp = dynamic_cast(p); + if (!vp) + return false; + + if (d->_ViewProviderMap.find(vp->getObject()) == d->_ViewProviderMap.end()) return false; View3DInventor *activeView = dynamic_cast(getActiveView()); @@ -1044,7 +1049,7 @@ void Document::createView(const Base::Type& typeId) View3DInventor* firstView = 0; QGLWidget* shareWidget = 0; if (!theViews.empty()) { - firstView = dynamic_cast(theViews.front()); + firstView = static_cast(theViews.front()); shareWidget = qobject_cast(firstView->getViewer()->getGLWidget()); } diff --git a/src/Gui/GuiApplication.cpp b/src/Gui/GuiApplication.cpp index f5d7772a7..4f738afd4 100644 --- a/src/Gui/GuiApplication.cpp +++ b/src/Gui/GuiApplication.cpp @@ -70,7 +70,7 @@ GUIApplication::~GUIApplication() bool GUIApplication::notify (QObject * receiver, QEvent * event) { - if (!receiver && event) { + if (!receiver) { Base::Console().Log("GUIApplication::notify: Unexpected null receiver, event type: %d\n", (int)event->type()); } diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index ec0e5f6b5..f2d6e30a4 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -841,7 +841,8 @@ void View3DInventorViewer::setNavigationType(Base::Type t) NavigationStyle* ns = static_cast(base); ns->operator = (*this->navigation); - delete this->navigation; + if (this->navigation) + ns->operator = (*this->navigation); this->navigation = ns; this->navigation->setViewer(this); } diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp index 6593d9fef..3d34603d8 100644 --- a/src/Gui/WidgetFactory.cpp +++ b/src/Gui/WidgetFactory.cpp @@ -390,8 +390,11 @@ QWidget* WidgetFactoryInst::createPrefWidget(const char* sName, QWidget* parent, w->setParent(parent); try { - dynamic_cast(w)->setEntryName(sPref); - dynamic_cast(w)->restorePreferences(); + PrefWidget* pw = dynamic_cast(w); + if (pw) { + pw->setEntryName(sPref); + pw->restorePreferences(); + } } catch (...) { #ifdef FC_DEBUG