From 28b195d6e29dd122b40b92b2d00e169c1e8fede1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 4 Mar 2019 11:53:49 +0100 Subject: [PATCH] PVS issues: consistently define copy constructor and assignment operator remove superfluous casts initialize member variables in constructor avoid double assignment --- src/App/Transactions.h | 2 +- src/Base/Rotation.cpp | 13 +++++++++++++ src/Base/Rotation.h | 1 + src/Gui/DocumentPyImp.cpp | 3 ++- src/Gui/GLPainter.cpp | 11 ++++++++++- src/Gui/NavigationStyle.h | 1 + src/Gui/OnlineDocumentation.cpp | 2 +- src/Gui/SoFCVectorizeSVGAction.cpp | 8 +++++++- src/Gui/SoFCVectorizeU3DAction.cpp | 6 ++++++ src/Gui/SpaceballEvent.cpp | 2 +- src/Gui/SpaceballEvent.h | 1 - src/Gui/ViewProviderGeometryObject.cpp | 14 +++++++++----- src/Gui/WidgetFactory.h | 6 +++--- src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp | 9 ++++----- src/Mod/Mesh/Gui/SoFCMeshObject.cpp | 3 +-- src/Mod/Mesh/Gui/SoFCMeshObject.h | 3 +++ 16 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/App/Transactions.h b/src/App/Transactions.h index e8b9ef97ce..3f135504e1 100644 --- a/src/App/Transactions.h +++ b/src/App/Transactions.h @@ -161,7 +161,7 @@ public: */ virtual void* Produce () const { - return (void*)(new CLASS); + return (new CLASS); } }; diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index d1ebc6b9f5..108566a1aa 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -90,6 +90,19 @@ Rotation::Rotation(const Rotation& rot) this->_angle = rot._angle; } +void Rotation::operator = (const Rotation& rot) +{ + this->quat[0] = rot.quat[0]; + this->quat[1] = rot.quat[1]; + this->quat[2] = rot.quat[2]; + this->quat[3] = rot.quat[3]; + + this->_axis[0] = rot._axis[0]; + this->_axis[1] = rot._axis[1]; + this->_axis[2] = rot._axis[2]; + this->_angle = rot._angle; +} + const double * Rotation::getValue(void) const { return &this->quat[0]; diff --git a/src/Base/Rotation.h b/src/Base/Rotation.h index a39e9bd5be..679d07934d 100644 --- a/src/Base/Rotation.h +++ b/src/Base/Rotation.h @@ -81,6 +81,7 @@ public: bool operator!=(const Rotation & q) const; double & operator [] (unsigned short usIndex){return quat[usIndex];} const double & operator [] (unsigned short usIndex) const{return quat[usIndex];} + void operator = (const Rotation&); void multVec(const Vector3d & src, Vector3d & dst) const; void scaleAngle(const double scaleFactor); diff --git a/src/Gui/DocumentPyImp.cpp b/src/Gui/DocumentPyImp.cpp index f6d1eed385..f316b144ac 100644 --- a/src/Gui/DocumentPyImp.cpp +++ b/src/Gui/DocumentPyImp.cpp @@ -298,7 +298,8 @@ PyObject* DocumentPy::toggleTreeItem(PyObject *args) // get the gui document of the Assembly Item //ActiveAppDoc = Item->getDocument(); //ActiveGuiDoc = Gui::Application::Instance->getDocument(getDocumentPtr()); - Gui::ViewProviderDocumentObject* ActiveVp = dynamic_cast (getDocumentPtr()->getViewProvider(Object)) ; + Gui::ViewProviderDocumentObject* ActiveVp = dynamic_cast (getDocumentPtr()->getViewProvider(Object)); + assert(ActiveVp); switch(mod) { case 0: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::ToggleItem); break; case 1: getDocumentPtr()->signalExpandObject(*ActiveVp,Gui::CollapseItem); break; diff --git a/src/Gui/GLPainter.cpp b/src/Gui/GLPainter.cpp index f788cf145f..d3974da7d0 100644 --- a/src/Gui/GLPainter.cpp +++ b/src/Gui/GLPainter.cpp @@ -34,8 +34,17 @@ using namespace Gui; TYPESYSTEM_SOURCE_ABSTRACT(Gui::GLGraphicsItem, Base::BaseClass); -GLPainter::GLPainter() : viewer(0), width(0), height(0), logicOp(false), lineStipple(false) +GLPainter::GLPainter() + : viewer(0) + , width(0) + , height(0) + , logicOp(false) + , lineStipple(false) { + depthrange[0] = 0; + depthrange[1] = 0; + for (int i=0; i<16; i++) + projectionmatrix[i] = 0.0; } GLPainter::~GLPainter() diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 127fa210ae..da1a311e33 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -252,6 +252,7 @@ protected: //@} private: + NavigationStyle(const NavigationStyle&); struct NavigationStyleP* pimpl; friend struct NavigationStyleP; }; diff --git a/src/Gui/OnlineDocumentation.cpp b/src/Gui/OnlineDocumentation.cpp index 165873ff3e..28b5bd22b8 100644 --- a/src/Gui/OnlineDocumentation.cpp +++ b/src/Gui/OnlineDocumentation.cpp @@ -82,7 +82,7 @@ PythonOnlineHelp::~PythonOnlineHelp() QByteArray PythonOnlineHelp::loadResource(const QString& filename) const { - QString fn = filename; + QString fn; fn = filename.mid(1); QByteArray res; diff --git a/src/Gui/SoFCVectorizeSVGAction.cpp b/src/Gui/SoFCVectorizeSVGAction.cpp index 7ba0551da2..e36a366a9a 100644 --- a/src/Gui/SoFCVectorizeSVGAction.cpp +++ b/src/Gui/SoFCVectorizeSVGAction.cpp @@ -80,6 +80,10 @@ class SoVectorizeLine : public SoVectorizeItem { public: SoVectorizeLine(void) { this->type = LINE; + vidx[0] = 0; + vidx[1] = 0; + col[0] = 0; + col[1] = 0; this->pattern = 0xffff; this->width = 1.0f; } @@ -116,6 +120,8 @@ class SoVectorizeImage : public SoVectorizeItem { public: SoVectorizeImage(void) { this->type = IMAGE; + this->image.data = 0; + this->image.nc = 0; } SbVec2f pos; // pos in normalized coordinates @@ -337,7 +343,7 @@ void SoFCVectorizeSVGActionP::printLine(const SoVectorizeLine * item) const v[i][1] = ((1.0f-v[i][1]) * mul[1]) + add[1]; c[i].setPackedValue(item->col[i], t[i]); } - uint32_t cc = c->getPackedValue(); + uint32_t cc = c[0].getPackedValue(); std::ostream& str = publ->getSVGOutput()->getFileStream(); str << "type = LINE; + vidx[0] = 0; + vidx[1] = 0; + col[0] = 0; + col[1] = 0; this->pattern = 0xffff; this->width = 1.0f; } @@ -117,6 +121,8 @@ class SoVectorizeImage : public SoVectorizeItem { public: SoVectorizeImage(void) { this->type = IMAGE; + this->image.data = 0; + this->image.nc = 0; } SbVec2f pos; // pos in normalized coordinates diff --git a/src/Gui/SpaceballEvent.cpp b/src/Gui/SpaceballEvent.cpp index e9e94b24f5..d420dd434e 100644 --- a/src/Gui/SpaceballEvent.cpp +++ b/src/Gui/SpaceballEvent.cpp @@ -35,7 +35,7 @@ EventBase::EventBase(QEvent::Type event) : QInputEvent(static_cast } MotionEvent::MotionEvent() : EventBase(static_cast(MotionEventType)), - xTrans(0), yTrans(0), zTrans(0), xRot(0), yRot(0), zRot(0), handled(false) + xTrans(0), yTrans(0), zTrans(0), xRot(0), yRot(0), zRot(0) { } diff --git a/src/Gui/SpaceballEvent.h b/src/Gui/SpaceballEvent.h index b07113e56a..6478141e4e 100644 --- a/src/Gui/SpaceballEvent.h +++ b/src/Gui/SpaceballEvent.h @@ -65,7 +65,6 @@ namespace Spaceball int xRot; int yRot; int zRot; - bool handled; }; class ButtonEvent : public EventBase diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index 7f94d408f5..47fd89560b 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -286,13 +286,17 @@ void ViewProviderGeometryObject::setSelectable(bool selectable) for (int i=0;i(pathList[i]->getTail()); if (selectable) { - selNode->selectionMode = SoFCSelection::SEL_ON; - selNode->highlightMode = SoFCSelection::AUTO; + if (selNode) { + selNode->selectionMode = SoFCSelection::SEL_ON; + selNode->highlightMode = SoFCSelection::AUTO; + } } else { - selNode->selectionMode = SoFCSelection::SEL_OFF; - selNode->highlightMode = SoFCSelection::OFF; - selNode->selected = SoFCSelection::NOTSELECTED; + if (selNode) { + selNode->selectionMode = SoFCSelection::SEL_OFF; + selNode->highlightMode = SoFCSelection::OFF; + selNode->selected = SoFCSelection::NOTSELECTED; + } } } } diff --git a/src/Gui/WidgetFactory.h b/src/Gui/WidgetFactory.h index 737a20e849..811bd0e6f0 100644 --- a/src/Gui/WidgetFactory.h +++ b/src/Gui/WidgetFactory.h @@ -173,7 +173,7 @@ public: */ virtual void* Produce () const { - return (void*)(new CLASS); + return (new CLASS); } }; @@ -212,7 +212,7 @@ public: */ virtual void* Produce () const { - return (void*)(new CLASS); + return (new CLASS); } }; @@ -295,7 +295,7 @@ public: */ virtual void* Produce () const { - return (void*)(new CLASS); + return (new CLASS); } }; diff --git a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp index 32a717e0f4..11e262c808 100644 --- a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp +++ b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp @@ -496,7 +496,7 @@ void SoFCIndexedFaceSet::GLRender(SoGLRenderAction *action) // use VBO for fast rendering if possible if (useVBO) { if (updateGLArray.getValue()) { - updateGLArray = false; + updateGLArray.setValue(false); generateGLArrays(action); } @@ -533,7 +533,7 @@ void SoFCIndexedFaceSet::drawFaces(SoGLRenderAction *action) SoMaterialBundle mb(action); mb.sendFirst(); if (updateGLArray.getValue()) { - updateGLArray = false; + updateGLArray.setValue(false); generateGLArrays(action); } render.renderFacesGLArray(action); @@ -670,7 +670,7 @@ void SoFCIndexedFaceSet::drawCoords(const SoGLCoordinateElement * const vertexli void SoFCIndexedFaceSet::invalidate() { - updateGLArray = true; + updateGLArray.setValue(true); } void SoFCIndexedFaceSet::generateGLArrays(SoGLRenderAction * action) @@ -977,8 +977,7 @@ void SoFCIndexedFaceSet::stopSelection(SoAction * action) delete [] selectBuf; selectBuf = 0; - bool sorted = true; - if(sorted) std::sort(hit.begin(),hit.end()); + std::sort(hit.begin(),hit.end()); Gui::SoGLSelectAction *doaction = static_cast(action); doaction->indices.reserve(hit.size()); diff --git a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp index cf930253d5..8313c69f6f 100644 --- a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp +++ b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp @@ -1053,8 +1053,7 @@ void SoFCMeshObjectShape::stopSelection(SoAction * action, const Mesh::MeshObjec delete [] selectBuf; selectBuf = 0; - bool sorted = true; - if(sorted) std::sort(hit.begin(),hit.end()); + std::sort(hit.begin(),hit.end()); Gui::SoGLSelectAction *doaction = static_cast(action); doaction->indices.reserve(hit.size()); diff --git a/src/Mod/Mesh/Gui/SoFCMeshObject.h b/src/Mod/Mesh/Gui/SoFCMeshObject.h index 992aa7c6c1..af26cb486f 100644 --- a/src/Mod/Mesh/Gui/SoFCMeshObject.h +++ b/src/Mod/Mesh/Gui/SoFCMeshObject.h @@ -49,6 +49,9 @@ class MeshGuiExport SoSFMeshObject : public SoSField { public: static void initClass(void); + +private: + SoSFMeshObject(const SoSFMeshObject&); }; // -------------------------------------------------------