From 4a494fec6916f30a69948dc62e86e5b968916309 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 19 Jul 2020 16:21:20 +0200 Subject: [PATCH] Coverity: Dereference null return value --- src/Gui/Tree.cpp | 4 ++-- .../PartDesign/Gui/TaskDressUpParameters.cpp | 22 ++++++++++--------- src/Mod/TechDraw/App/DrawViewPartPyImp.cpp | 6 +++++ src/Mod/TechDraw/Gui/TaskRichAnno.cpp | 4 +++- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index e5023d2ffb..496c85bdf1 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -1823,8 +1823,8 @@ void TreeWidget::dropEvent(QDropEvent *event) std::string dropName; ss.str(""); if(da == Qt::LinkAction) { - if(targetItemObj->getParentItem()) { - auto parentItem = targetItemObj->getParentItem(); + auto parentItem = targetItemObj->getParentItem(); + if (parentItem) { ss << Command::getObjectCmd( parentItem->object()->getObject(),0,".replaceObject(",true) << Command::getObjectCmd(targetObj) << "," diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index ee2409da77..75f3663b34 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -205,17 +205,19 @@ void TaskDressUpParameters::setSelection(QListWidgetItem* current) { std::string docName = DressUpView->getObject()->getDocument()->getName(); // get the name of the body we are in Part::BodyBase* body = PartDesign::Body::findBodyOf(DressUpView->getObject()); - std::string objName = body->getNameInDocument(); + if (body) { + std::string objName = body->getNameInDocument(); - // hide fillet to see the original edge - // (a fillet creates new edges so that the original one is not available) - hideObject(); - // highlight all objects in the list - DressUpView->highlightReferences(true); - // clear existing selection because only the current item is highlighted, not all selected ones to keep the overview - Gui::Selection().clearSelection(); - // highligh the selected item - Gui::Selection().addSelection(docName.c_str(), objName.c_str(), subName.c_str(), 0, 0, 0); + // hide fillet to see the original edge + // (a fillet creates new edges so that the original one is not available) + hideObject(); + // highlight all objects in the list + DressUpView->highlightReferences(true); + // clear existing selection because only the current item is highlighted, not all selected ones to keep the overview + Gui::Selection().clearSelection(); + // highligh the selected item + Gui::Selection().addSelection(docName.c_str(), objName.c_str(), subName.c_str(), 0, 0, 0); + } } } diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index 35ff2422b8..c4c8d4654a 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -659,6 +659,9 @@ PyObject* DrawViewPartPy::getEdgeByIndex(PyObject *args) //this is scaled and +Yup //need unscaled and +Ydown TechDraw::BaseGeom* geom = dvp->getGeomByIndex(edgeIndex); + if (geom == nullptr) { + throw Py::ValueError("wrong edgeIndex"); + } TopoDS_Shape temp = TechDraw::mirrorShapeVec(geom->occEdge, Base::Vector3d(0.0, 0.0, 0.0), @@ -679,6 +682,9 @@ PyObject* DrawViewPartPy::getVertexByIndex(PyObject *args) //this is scaled and +Yup //need unscaled and +Ydown TechDraw::Vertex* vert = dvp->getProjVertexByIndex(vertexIndex); + if (vert == nullptr) { + throw Py::ValueError("wrong vertIndex"); + } Base::Vector3d point = DrawUtil::invertY(vert->point()) / dvp->getScale(); gp_Pnt gPoint(point.x, point.y, point.z); diff --git a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp index 1ade732bb9..656809a2b5 100644 --- a/src/Mod/TechDraw/Gui/TaskRichAnno.cpp +++ b/src/Mod/TechDraw/Gui/TaskRichAnno.cpp @@ -389,7 +389,9 @@ void TaskRichAnno::createAnnoFeature() if (m_basePage != nullptr) { m_basePage->touch(); } - m_annoFeat->requestPaint(); + if (m_annoFeat != nullptr) { + m_annoFeat->requestPaint(); + } } void TaskRichAnno::updateAnnoFeature()