From 6687eabe9b9db74285bd2e67d7470e42727b4cfb Mon Sep 17 00:00:00 2001 From: Christopher Tenter Date: Tue, 29 Nov 2016 16:41:37 +0100 Subject: [PATCH] fix several cppcheck warnings --- ACG/GL/GLState.cc | 10 +++++----- ACG/GL/ShaderGenerator.cc | 20 +++++++++++++++---- ACG/Scenegraph/TranslationManipulatorNode.cc | 2 +- ACG/ShaderUtils/UniformPool.cc | 3 ++- ACG/ShaderUtils/UniformPool.hh | 2 +- ACG/Utils/Tracing.cc | 2 +- ObjectTypes/PolyLine/PolyLineT.cc | 4 ++-- ObjectTypes/PolyLine/PolyLineT.hh | 4 ++-- ObjectTypes/Skeleton/JointT.cc | 2 +- ObjectTypes/Skeleton/JointT.hh | 2 +- ObjectTypes/SplatCloud/SplatCloudNode.cc | 11 +++------- .../Plugin-FileOBJ/FileOBJ.cc | 12 +++++------ .../Plugin-FileOVM/FileOpenVolumeMesh.cc | 2 +- 13 files changed, 42 insertions(+), 34 deletions(-) diff --git a/ACG/GL/GLState.cc b/ACG/GL/GLState.cc index 569e81e8d..14f7e1c6a 100644 --- a/ACG/GL/GLState.cc +++ b/ACG/GL/GLState.cc @@ -86,7 +86,7 @@ const float GLState::default_shininess(100.f); bool GLState::depthFuncLock_ = false; bool GLState::depthRangeLock_ = false; -bool GLState::blendFuncSeparateLock_[2] = { false }; +bool GLState::blendFuncSeparateLock_[] = { false }; bool GLState::blendEquationLock_ = false; bool GLState::blendColorLock_ = false; bool GLState::alphaFuncLock_ = false; @@ -101,9 +101,9 @@ bool GLState::programLock_ = false; std::deque GLState::stateStack_; std::bitset<0xFFFF+1> GLState::glStateLock_; -int GLState::glBufferTargetLock_[4] = {0}; -int GLState::glTextureStageLock_[16] = {0}; -bool GLState::framebufferLock_[2] = {false}; +int GLState::glBufferTargetLock_[] = {0}; +int GLState::glTextureStageLock_[] = {0}; +bool GLState::framebufferLock_[] = {false}; int GLState::maxTextureCoords_ = 0; int GLState::maxCombinedTextureImageUnits_ = 0; int GLState::maxDrawBuffers_ = 0; @@ -1142,7 +1142,7 @@ bool GLState::color_picking () const //----------------------------------------------------------------------------- -GLenum GLState::glStateCaps[95] = {GL_ALPHA_TEST, +GLenum GLState::glStateCaps[] = {GL_ALPHA_TEST, GL_AUTO_NORMAL, GL_MAP2_VERTEX_3, GL_MAP2_VERTEX_4, diff --git a/ACG/GL/ShaderGenerator.cc b/ACG/GL/ShaderGenerator.cc index ecd3f4918..2b99a2d67 100644 --- a/ACG/GL/ShaderGenerator.cc +++ b/ACG/GL/ShaderGenerator.cc @@ -2336,12 +2336,24 @@ void ShaderProgGenerator::scanShaderTemplate(QStringList& _templateSrc, QString QByteArray lineBytes = trimmedLine.toUtf8(); int templateVersion = 0; - if (sscanf(lineBytes.constData(), "#version %d", &templateVersion) == 1) + if (trimmedLine.startsWith("#version ")) { - desc_.version = std::max(templateVersion, desc_.version); + QStringList tokens = trimmedLine.split(' '); - // remove version line from template since this is added later in the build functions - it = _templateSrc.erase(it); + if (tokens.size() > 1) + { + // templateVersion + bool convOk = false; + templateVersion = tokens.at(1).toInt(&convOk); + + if (convOk) + { + desc_.version = std::max(templateVersion, desc_.version); + + // remove version line from template since this is added later in the build functions + it = _templateSrc.erase(it); + } + } } // scan layout() directive else if (trimmedLine.startsWith("layout(") || trimmedLine.startsWith("layout (")) diff --git a/ACG/Scenegraph/TranslationManipulatorNode.cc b/ACG/Scenegraph/TranslationManipulatorNode.cc index 042ba5265..9b8143f86 100644 --- a/ACG/Scenegraph/TranslationManipulatorNode.cc +++ b/ACG/Scenegraph/TranslationManipulatorNode.cc @@ -966,7 +966,6 @@ TranslationManipulatorNode::mouseEvent(GLState& _state, QMouseEvent* _event) Vec3d oldPoint3D; Vec2i newPoint2D(_event->pos().x(), _event->pos().y()); Vec3d newPoint3D; - bool rot[3], trans[3]; unsigned int i; bool lockOldPoint = false; @@ -1135,6 +1134,7 @@ TranslationManipulatorNode::mouseEvent(GLState& _state, QMouseEvent* _event) } // set action for the different modes + bool rot[3], trans[3]; switch (mode_) { case Rotation: for (i = 0; i < 3; i++) { diff --git a/ACG/ShaderUtils/UniformPool.cc b/ACG/ShaderUtils/UniformPool.cc index 7ddb0f9f3..eaa3b1e1f 100644 --- a/ACG/ShaderUtils/UniformPool.cc +++ b/ACG/ShaderUtils/UniformPool.cc @@ -84,8 +84,9 @@ namespace GLSL { } - void UniformPool::operator =(const UniformPool& _other) { + UniformPool& UniformPool::operator =(const UniformPool& _other) { addPool(_other); + return *this; } void UniformPool::clear() { diff --git a/ACG/ShaderUtils/UniformPool.hh b/ACG/ShaderUtils/UniformPool.hh index ed720ebc1..9962dc5ef 100644 --- a/ACG/ShaderUtils/UniformPool.hh +++ b/ACG/ShaderUtils/UniformPool.hh @@ -124,7 +124,7 @@ namespace GLSL { /** \brief copy * */ - void operator =(const UniformPool& _other); + UniformPool& operator =(const UniformPool& _other); private: struct UniformBase { diff --git a/ACG/Utils/Tracing.cc b/ACG/Utils/Tracing.cc index 53350261d..878705d87 100644 --- a/ACG/Utils/Tracing.cc +++ b/ACG/Utils/Tracing.cc @@ -69,7 +69,7 @@ namespace ACG { // static variables -char Tracing::progress_[4] = { '-', '\\', '|', '/' }; +char Tracing::progress_[] = { '-', '\\', '|', '/' }; unsigned char Tracing::idx_ = 0; diff --git a/ObjectTypes/PolyLine/PolyLineT.cc b/ObjectTypes/PolyLine/PolyLineT.cc index a825afe9b..9dbf9b702 100644 --- a/ObjectTypes/PolyLine/PolyLineT.cc +++ b/ObjectTypes/PolyLine/PolyLineT.cc @@ -1527,8 +1527,8 @@ PolyLineT:: edge_points_in_segment( const MeshT& _mesh, const Point& _p0, const Point& _p1, - const typename MeshT::FaceHandle _fh0, - const typename MeshT::FaceHandle _fh1, + const typename MeshT::FaceHandle& _fh0, + const typename MeshT::FaceHandle& _fh1, std::vector & _points, std::vector& _ehandles ) { diff --git a/ObjectTypes/PolyLine/PolyLineT.hh b/ObjectTypes/PolyLine/PolyLineT.hh index d0229dec8..47a9a78d5 100644 --- a/ObjectTypes/PolyLine/PolyLineT.hh +++ b/ObjectTypes/PolyLine/PolyLineT.hh @@ -641,8 +641,8 @@ private: void edge_points_in_segment( const MeshT& _mesh, const Point& _p0, const Point& _p1, - const typename MeshT::FaceHandle _fh0, - const typename MeshT::FaceHandle _fh1, + const typename MeshT::FaceHandle& _fh0, + const typename MeshT::FaceHandle& _fh1, std::vector & _points, std::vector& _ehandles ); diff --git a/ObjectTypes/Skeleton/JointT.cc b/ObjectTypes/Skeleton/JointT.cc index bbfa8573d..790396190 100644 --- a/ObjectTypes/Skeleton/JointT.cc +++ b/ObjectTypes/Skeleton/JointT.cc @@ -257,7 +257,7 @@ inline std::string JointT::name() const { //----------------------------------------------------------------------------------------------------- template -inline void JointT::setName(const std::string _name) { +inline void JointT::setName(const std::string& _name) { name_ = _name; } diff --git a/ObjectTypes/Skeleton/JointT.hh b/ObjectTypes/Skeleton/JointT.hh index a8c22002b..5f7f4ec30 100644 --- a/ObjectTypes/Skeleton/JointT.hh +++ b/ObjectTypes/Skeleton/JointT.hh @@ -113,7 +113,7 @@ public: /// Access the name of the joint inline std::string name() const; - inline void setName(const std::string _name); + inline void setName(const std::string& _name); private: /// An unique identifier, guaranteed to be part of a continuous sequence starting from 0 diff --git a/ObjectTypes/SplatCloud/SplatCloudNode.cc b/ObjectTypes/SplatCloud/SplatCloudNode.cc index 12f12f848..057f8dec8 100644 --- a/ObjectTypes/SplatCloud/SplatCloudNode.cc +++ b/ObjectTypes/SplatCloud/SplatCloudNode.cc @@ -97,9 +97,9 @@ SplatCloudNode::SplatCloudNode( const SplatCloud &_splatCloud, BaseNode *_parent defaultColor_ ( Color (0,0,0) ), defaultNormal_ ( Normal (0,0,0) ), defaultPointsize_ ( Pointsize( 0.0) ), - splatsDrawMode_ ( DrawModes::NONE ), - dotsDrawMode_ ( DrawModes::NONE ), - pointsDrawMode_ ( DrawModes::NONE ), + splatsDrawMode_ ( DrawModes::addDrawMode( "Splats" ) ), + dotsDrawMode_ ( DrawModes::addDrawMode( "Dots" ) ), + pointsDrawMode_ ( DrawModes::addDrawMode( "Points" ) ), pickingBaseIndex_ ( 0 ), pickDrawMode_ ( DrawModes::NONE ), // TODO: hack, see enterPick() vboGlId_ ( 0 ), @@ -112,11 +112,6 @@ SplatCloudNode::SplatCloudNode( const SplatCloud &_splatCloud, BaseNode *_parent vboSelectionsOffset_( -1 ), vboPickColorsOffset_( -1 ) { - // add (possibly) new drawmodes - pointsDrawMode_ = DrawModes::addDrawMode( "Points" ); - dotsDrawMode_ = DrawModes::addDrawMode( "Dots" ); - splatsDrawMode_ = DrawModes::addDrawMode( "Splats" ); - // create a new VBO (will be invalid and rebuilt the next time drawn (or picked)) createVBO(); } diff --git a/PluginCollection-FilePlugins/Plugin-FileOBJ/FileOBJ.cc b/PluginCollection-FilePlugins/Plugin-FileOBJ/FileOBJ.cc index 4b1d83e39..6e3d6c727 100644 --- a/PluginCollection-FilePlugins/Plugin-FileOBJ/FileOBJ.cc +++ b/PluginCollection-FilePlugins/Plugin-FileOBJ/FileOBJ.cc @@ -1048,9 +1048,9 @@ void FileOBJPlugin::readOBJFile(QByteArray& _bufferedFile, QString _filename, OB // Read knots at the beginning before the indices if ( keyWrd == QLatin1String("curv") ) { - double trash; - trash = getDouble(lineData); - trash = getDouble(lineData); + // skip next two doubles in stream + getDouble(lineData); + getDouble(lineData); } @@ -1576,9 +1576,9 @@ void FileOBJPlugin::checkTypes(QByteArray& _bufferedFile, QString _filename, OBJ // Read knots at the beginning before the indices if ( keyWrd == QLatin1String("curv") ) { - double trash; - trash = getDouble(lineData); - trash = getDouble(lineData); + // skip next two doubles in stream + getDouble(lineData); + getDouble(lineData); } // work on the line until nothing left to read diff --git a/PluginCollection-FilePlugins/Plugin-FileOVM/FileOpenVolumeMesh.cc b/PluginCollection-FilePlugins/Plugin-FileOVM/FileOpenVolumeMesh.cc index 7056e064b..c6640f418 100644 --- a/PluginCollection-FilePlugins/Plugin-FileOVM/FileOpenVolumeMesh.cc +++ b/PluginCollection-FilePlugins/Plugin-FileOVM/FileOpenVolumeMesh.cc @@ -153,7 +153,6 @@ int FileOpenVolumeMeshPlugin::loadObject(QString _filename) { int id = -1; bool hexMesh = false; - bool tetMesh = false; if(!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 0) { hexMesh = fileManager_.isHexahedralMesh(_filename.toStdString()); @@ -162,6 +161,7 @@ int FileOpenVolumeMeshPlugin::loadObject(QString _filename) { } #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT + bool tetMesh = false; if(!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 0) { tetMesh = fileManager_.isTetrahedralMesh(_filename.toStdString()); } else if (!OpenFlipper::Options::nogui() && typeCheck_->currentIndex() == 3) { -- GitLab