From 373606fb50bb97f874219c019f369da20e2f3e2c Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sun, 19 Apr 2015 11:30:22 +0000 Subject: [PATCH] coverity fixes --- CMakeLists.txt | 2 +- Common/DefaultOptions.h | 2 +- Common/rtree.h | 4 ++++ Geo/GFaceCompound.cpp | 10 ++++++++++ Geo/GenericFace.cpp | 14 +++++++------- Mesh/Generator.cpp | 5 +++-- Plugin/FaultZone.cpp | 10 +++++----- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 151785ec09..62ef6f15e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ opt(WRAP_PYTHON "Enable generation of Python wrappers" OFF) set(GMSH_MAJOR_VERSION 2) set(GMSH_MINOR_VERSION 9) -set(GMSH_PATCH_VERSION 3) +set(GMSH_PATCH_VERSION 4) set(GMSH_EXTRA_VERSION "" CACHE STRING "Gmsh extra version string") set(GMSH_VERSION "${GMSH_MAJOR_VERSION}.${GMSH_MINOR_VERSION}") diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 92cd79977e..af580608d6 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -1699,7 +1699,7 @@ StringXColor GeneralOptions_Color[] = { {245, 245, 245, 255}, {255, 255, 255, 255}, {245, 245, 245, 255}, {50, 50, 50, 255}, "Background color" }, { F|O, "BackgroundGradient" , opt_general_color_background_gradient , - {165, 165, 165, 255}, {208, 215, 255, 255}, {165, 165, 165, 255}, {50, 50, 50, 255}, + {185, 185, 185, 255}, {208, 215, 255, 255}, {185, 185, 185, 255}, {50, 50, 50, 255}, "Background gradient color" }, { F|O, "Foreground" , opt_general_color_foreground , {85, 85, 85, 255}, {85, 85, 85, 255}, {85, 85, 85, 255}, {170, 170, 170, 255}, diff --git a/Common/rtree.h b/Common/rtree.h index c4ea149046..619038aadb 100644 --- a/Common/rtree.h +++ b/Common/rtree.h @@ -940,6 +940,9 @@ bool RTREE_QUAL::InsertRectRec(Rect* a_rect, const DATATYPE& a_id, Node* a_node, if(a_node->m_level > a_level) { index = PickBranch(a_rect, a_node); + + if(index < 0) return false; // Added for Gmsh + if (!InsertRectRec(a_rect, a_id, a_node->m_branch[index].m_child, &otherNode, a_level)) { // Child was not split @@ -1434,6 +1437,7 @@ void RTREE_QUAL::Classify(int a_index, int a_group, PartitionVars* a_parVars) { ASSERT(a_parVars); ASSERT(!a_parVars->m_taken[a_index]); + ASSERT(a_index >= 0); // Added for Gmsh a_parVars->m_partition[a_index] = a_group; a_parVars->m_taken[a_index] = true; diff --git a/Geo/GFaceCompound.cpp b/Geo/GFaceCompound.cpp index f11549ca8d..fdd3479dcc 100644 --- a/Geo/GFaceCompound.cpp +++ b/Geo/GFaceCompound.cpp @@ -2878,21 +2878,31 @@ void GFaceCompound::printStuff(int iNewton) const } FILE * uvy = Fopen(name2,"w"); if(!uvy){ + fclose(uvx); Msg::Error("Could not open file '%s'", name2); return; } FILE * uvz = Fopen(name3,"w"); if(!uvz){ + fclose(uvx); + fclose(uvy); Msg::Error("Could not open file '%s'", name3); return; } FILE * xyzu = Fopen(name4,"w"); if(!xyzu){ + fclose(uvx); + fclose(uvy); + fclose(uvz); Msg::Error("Could not open file '%s'", name4); return; } FILE * xyzv = Fopen(name5,"w"); if(!xyzv){ + fclose(uvx); + fclose(uvy); + fclose(uvz); + fclose(xyzu); Msg::Error("Could not open file '%s'", name5); return; } diff --git a/Geo/GenericFace.cpp b/Geo/GenericFace.cpp index a8047b2693..94a5360c87 100644 --- a/Geo/GenericFace.cpp +++ b/Geo/GenericFace.cpp @@ -53,7 +53,7 @@ SVector3 GenericFace::normal(const SPoint2 ¶m) const { std::vector<double> res(3,0.); std::vector<double> par(2,0.); - for (int i=0;i<3;i++) par[i] = param[i]; + for (int i = 0; i < 2; i++) par[i] = param[i]; if (!FaceEvalNormal) Msg::Fatal("Genericface::ERROR: Callback FaceEvalNormal not set"); bool ok = FaceEvalNormal(id,par,res); if (!ok) Msg::Error("GenericFace::ERROR from FaceEvalNormal ! " ); @@ -66,7 +66,7 @@ Pair<SVector3,SVector3> GenericFace::firstDer(const SPoint2 ¶m) const std::vector<double> deru(3,0.); std::vector<double> derv(3,0.); std::vector<double> par(2,0.); - for (int i=0;i<3;i++) par[i] = param[i]; + for (int i = 0; i < 2; i++) par[i] = param[i]; bool ok = FaceFirstDer(id,par,deru,derv); if (!ok) Msg::Error("GenericFace::ERROR from FaceFirstDer ! " ); return Pair<SVector3,SVector3>(SVector3(deru[0],deru[1],deru[2]), @@ -79,7 +79,7 @@ void GenericFace::secondDer(const SPoint2 ¶m,SVector3 *dudu, SVector3 *dvdv, std::vector<double> dervv(3,0.); std::vector<double> deruv(3,0.); std::vector<double> par(2,0.); - for (int i=0;i<2;i++) par[i] = param[i]; + for (int i = 0; i < 2; i++) par[i] = param[i]; if (!FaceSecondDer) Msg::Fatal("Genericface::ERROR: Callback FaceSecondDer not set"); bool ok = FaceSecondDer(id,par,deruu,dervv,deruv); if (!ok) Msg::Error("GenericFace::ERROR from FaceSecondDer ! " ); @@ -190,7 +190,7 @@ double GenericFace::curvatureMax(const SPoint2 ¶m) const std::vector<double> dirMin(3,0.); double curvMax,curvMin; std::vector<double> par(2,0.); - for (int i=0;i<2;i++) par[i] = param[i]; + for (int i = 0; i < 2; i++) par[i] = param[i]; if (!FaceCurvatures) Msg::Fatal("Genericface::ERROR: Callback FaceCurvatures not set"); bool ok = FaceCurvatures(id,par,dirMax,dirMin,curvMax,curvMin); if (!ok) Msg::Error("GenericFace::ERROR from FaceCurvatures ! " ); @@ -201,7 +201,7 @@ double GenericFace::curvatures(const SPoint2 &_param,SVector3 *_dirMax,SVector3 double *curvMax,double *curvMin) const { std::vector<double> param(2,0.); - for (int i=0;i<2;i++) param[i] = _param[i]; + for (int i = 0; i < 2; i++) param[i] = _param[i]; std::vector<double> dirMax(3,0.); std::vector<double> dirMin(3,0.); @@ -218,7 +218,7 @@ bool GenericFace::containsPoint(const SPoint3 &pt) const { bool res; std::vector<double> queryPoint(3,0.); - for (int i=0;i<3;i++) queryPoint[i] = pt[i]; + for (int i = 0; i < 3; i++) queryPoint[i] = pt[i]; if (!FaceContainsPointFromXYZ) Msg::Fatal("Genericface::ERROR: Callback FaceContainsPointFromXYZ not set"); bool ok = FaceContainsPointFromXYZ(id,queryPoint,res); if (!ok) Msg::Error("GenericFace::containsPoint::ERROR from FaceContainsPointFromXYZ ! " ); @@ -239,7 +239,7 @@ void GenericFace::createLoops() l_dirs.clear(); for (std::set<int>::iterator it_loop = loopsnumber.begin(); - it_loop!=loopsnumber.end();it_loop++){// for each loop + it_loop != loopsnumber.end(); it_loop++){// for each loop std::pair<std::multimap<int, std::pair<GEdge*,int> >::iterator, std::multimap<int, std::pair<GEdge*,int> >::iterator> range = bnd.equal_range(*it_loop); diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp index daeaf2f3f9..30ab454e94 100644 --- a/Mesh/Generator.cpp +++ b/Mesh/Generator.cpp @@ -270,8 +270,9 @@ static void PrintMesh2dStatistics(GModel *m) else return; - if(statreport){ - Msg::Error("Could not open file '%s'", CTX::instance()->meshStatReportFileName.c_str()); + if(!statreport){ + Msg::Error("Could not open file '%s'", + CTX::instance()->meshStatReportFileName.c_str()); return; } diff --git a/Plugin/FaultZone.cpp b/Plugin/FaultZone.cpp index e42e251286..516fac0653 100644 --- a/Plugin/FaultZone.cpp +++ b/Plugin/FaultZone.cpp @@ -565,7 +565,7 @@ void GMSH_FaultZoneMesher::CreateJointElements(GModel* gModel, GFace* gFace, continue; SPoint3 bary = mElem->barycenter(); - MVertex* mVerts[8]; + std::vector<MVertex*> mVerts(8, NULL); // check orientation SVector3 nor = _vectNormByFissure[gEdge]; @@ -579,11 +579,11 @@ void GMSH_FaultZoneMesher::CreateJointElements(GModel* gModel, GFace* gFace, for(int i = 0; i < mElem->getNumVertices(); i++){ MVertex *mVert = mElem->getVertex(i); - int j = (changeOri && i<2)?!i:i; - if (j<2) // adding intern node + int j = (changeOri && i < 2) ? !i : i; + if (j < 2) // adding intern node mVerts[_numNodeJoint[j]] = _nodeJointByHeavOrJunctionNode[mVert]; - if (_nodeByHeavNode.find( mVert ) != _nodeByHeavNode.end()){ + if (_nodeByHeavNode.find(mVert) != _nodeByHeavNode.end()){ // adding upper and under nodes mVerts[_numNodeHeavInf[j]] = mVert; mVerts[_numNodeHeavSup[j]] = _nodeByHeavNode[mVert]; @@ -619,7 +619,7 @@ void GMSH_FaultZoneMesher::CreateJointElements(GModel* gModel, GFace* gFace, // the new GEntity (created here) for(int j =0; j<8; j++){ MVertex *mVert = mVerts[j]; - assert(mVert!= NULL); + assert(mVert != NULL); if (mVert->onWhat() == 0){ mVert->setEntity(jointFace); jointFace->addMeshVertex(mVert); -- GitLab