From b695601ce2fbf723059e6872f92feb42ee078207 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <incardon@mpi-cbg.de>
Date: Sat, 2 Mar 2019 21:32:15 +0100
Subject: [PATCH] Fixing coverty errors

---
 src/Graph/CartesianGraphFactory.hpp            | 18 +++++++++---------
 src/Grid/grid_sm.hpp                           |  2 +-
 src/NN/CellList/CellDecomposer.hpp             |  4 ++++
 src/NN/CellList/CellList.hpp                   | 12 ++++++------
 src/NN/CellList/CellNNIterator.hpp             | 17 +++++++++--------
 src/NN/CellList/CellNNIteratorRuntime.hpp      |  4 ++--
 .../CellList/cuda/Cuda_cell_list_util_func.hpp |  2 +-
 src/NN/VerletList/VerletListFast.hpp           |  2 +-
 src/Space/Shape/HyperCube.hpp                  |  3 +++
 src/Space/Shape/Point.hpp                      |  1 +
 src/util/compute_optimal_device_grid.hpp       |  2 ++
 11 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/src/Graph/CartesianGraphFactory.hpp b/src/Graph/CartesianGraphFactory.hpp
index d9638e03..9a99be27 100755
--- a/src/Graph/CartesianGraphFactory.hpp
+++ b/src/Graph/CartesianGraphFactory.hpp
@@ -230,7 +230,7 @@ public:
  * \tparam Graph Graph
  * \tparam pos Array of properties
  */
-template<int i, typename p, typename Graph, int ... pos>
+template<unsigned int dim, int i, typename p, typename Graph, int ... pos>
 struct fill_prop_by_type
 {
 
@@ -242,7 +242,7 @@ struct fill_prop_by_type
 
 	enum
 	{
-		value = ((sizeof...(pos) != 0) * (std::is_array<pos_prop_type>::value + 1))
+		value = ((sizeof...(pos) != 0 && dim <= 3) * (std::is_array<pos_prop_type>::value + 1))
 	};
 
 };
@@ -254,8 +254,8 @@ struct fill_prop_by_type
  * \tparam Graph Graph
  * \tparam pos Array of properties
  */
-template<typename p, typename Graph, int ... pos>
-struct fill_prop_by_type<0, p, Graph, pos...>
+template<unsigned int dim, typename p, typename Graph, int ... pos>
+struct fill_prop_by_type<dim, 0, p, Graph, pos...>
 {
 	enum
 	{
@@ -286,7 +286,7 @@ public:
 	 * \return the constructed graph
 	 *
 	 */
-	static Graph construct(const size_t (& sz)[dim], Box<dim,T> dom, const size_t(& bc)[dim])
+	static Graph construct(const size_t (& sz)[dim], Box<dim,T> & dom, const size_t(& bc)[dim])
 	{
 		// Calculate the size of the hyper-cubes on each dimension
 		T szd[dim];
@@ -335,7 +335,7 @@ public:
 
 			// vertex spatial properties functor
 
-			fill_prop<dim, lin_id, T, decltype(gp.vertex(g.LinId(key))), typename to_boost_vmpl<pos...>::type, fill_prop_by_type<sizeof...(pos), p, Graph, pos...>::value> flp(obj, szd, key, g, dom);
+			fill_prop<dim, lin_id, T, decltype(gp.vertex(g.LinId(key))), typename to_boost_vmpl<pos...>::type, fill_prop_by_type<dim,sizeof...(pos), p, Graph, pos...>::value> flp(obj, szd, key, g, dom);
 
 			// fill properties
 
@@ -407,7 +407,7 @@ public:
 	 * \return the constructed graph
 	 *
 	 */
-	static Graph construct(const size_t ( & sz)[dim], Box<dim,T> dom, const size_t(& bc)[dim])
+	static Graph construct(const size_t ( & sz)[dim], Box<dim,T> & dom, const size_t(& bc)[dim])
 	{
 		// Calculate the size of the hyper-cubes on each dimension
 
@@ -456,7 +456,7 @@ public:
 
 			// vertex spatial properties functor
 
-			fill_prop<dim, lin_id, T, decltype(gp.vertex(g.LinId(key))), typename to_boost_vmpl<pos...>::type, fill_prop_by_type<sizeof...(pos), p, Graph, pos...>::value> flp(obj, szd, key, g, dom);
+			fill_prop<dim, lin_id, T, decltype(gp.vertex(g.LinId(key))), typename to_boost_vmpl<pos...>::type, fill_prop_by_type<dim,sizeof...(pos), p, Graph, pos...>::value> flp(obj, szd, key, g, dom);
 
 			// fill properties
 
@@ -537,7 +537,7 @@ public:
 	 *
 	 */
 	template<int se, int id_prp, typename T, unsigned int dim_c, int ... pos>
-	static Graph construct(const size_t (&sz)[dim], Box<dim, T> dom, const size_t (& bc)[dim])
+	static Graph construct(const size_t (&sz)[dim], Box<dim, T> & dom, const size_t (& bc)[dim])
 	{
 		return Graph_constructor_impl<dim, id_prp, Graph, se, T, dim_c, pos...>::construct(sz, dom, bc);
 	}
diff --git a/src/Grid/grid_sm.hpp b/src/Grid/grid_sm.hpp
index 1530bf9d..25a14028 100755
--- a/src/Grid/grid_sm.hpp
+++ b/src/Grid/grid_sm.hpp
@@ -463,7 +463,7 @@ public:
 		mem_id lid = gk.get(0);
 		for (mem_id i = 1 ; i < N ; i++)
 		{
-			/* coverity[dead_error_begin */
+			/* coverity[dead_error_line] */
 			lid += gk.get(i) * sz_s[i-1];
 		}
 
diff --git a/src/NN/CellList/CellDecomposer.hpp b/src/NN/CellList/CellDecomposer.hpp
index bc1cf4ca..692f268f 100644
--- a/src/NN/CellList/CellDecomposer.hpp
+++ b/src/NN/CellList/CellDecomposer.hpp
@@ -1487,6 +1487,10 @@ public:
 	CellDecomposer_sm(const SpaceBox<dim,T> & box, const size_t (&div)[dim], Matrix<dim,T> & mat, const size_t pad)
 	:t(Matrix<dim,T>::identity(),box.getP1()),box(box),gr_cell()
 	{
+		// set div_wp to zero
+		for (size_t i = 0 ; i < dim ; i++)
+		{div_wp[i] = 0;}
+
 		Initialize(pad);
 	}
 
diff --git a/src/NN/CellList/CellList.hpp b/src/NN/CellList/CellList.hpp
index 69a04da5..93d2d66c 100644
--- a/src/NN/CellList/CellList.hpp
+++ b/src/NN/CellList/CellList.hpp
@@ -426,7 +426,7 @@ public:
 	//! Type of internal memory structure
 	typedef Mem_type Mem_type_type;
 
-	typedef CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,RUNTIME,vector_pos_type,NO_CHECK> SymNNIterator;
+	typedef CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,RUNTIME,NO_CHECK> SymNNIterator;
 
 	//! Object type that the structure store
 	typedef typename Mem_type::local_index_type value_type;
@@ -1004,7 +1004,7 @@ public:
 	 *
 	 */
 	template<unsigned int impl>
-	inline CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,(unsigned int)SYM,vector_pos_type,impl>
+	inline CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,(unsigned int)SYM,impl>
 	getNNIteratorSym(size_t cell, size_t p, const vector_pos_type & v)
 	{
 #ifdef SE_CLASS1
@@ -1012,7 +1012,7 @@ public:
 		{std::cerr << __FILE__ << ":" << __LINE__ << " Warning when you try to get a symmetric neighborhood iterator, you must construct the Cell-list in a symmetric way" << std::endl;}
 #endif
 
-		CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,SYM,vector_pos_type,impl> cln(cell,p,NNc_sym,*this,v);
+		CellNNIteratorSym<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,SYM,impl> cln(cell,p,NNc_sym,*this,v);
 		return cln;
 	}
 
@@ -1039,15 +1039,15 @@ public:
 	 *
 	 */
 	template<unsigned int impl>
-	inline CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform>,(unsigned int)SYM,impl>
-	getNNIteratorSymMP(size_t cell, size_t p, const openfpm::vector<Point<dim,T>> & v_p1, const openfpm::vector<Point<dim,T>> & v_p2)
+	inline CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,(unsigned int)SYM,impl>
+	getNNIteratorSymMP(size_t cell, size_t p, const vector_pos_type & v_p1, const vector_pos_type & v_p2)
 	{
 #ifdef SE_CLASS1
 		if (from_cd == false)
 			std::cerr << __FILE__ << ":" << __LINE__ << " Warning when you try to get a symmetric neighborhood iterator, you must construct the Cell-list in a symmetric way" << std::endl;
 #endif
 
-		CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform>,SYM,impl> cln(cell,p,NNc_sym,*this,v_p1,v_p2);
+		CellNNIteratorSymMP<dim,CellList<dim,T,Mem_type,transform,vector_pos_type>,vector_pos_type,SYM,impl> cln(cell,p,NNc_sym,*this,v_p1,v_p2);
 		return cln;
 	}
 
diff --git a/src/NN/CellList/CellNNIterator.hpp b/src/NN/CellList/CellNNIterator.hpp
index c146ed54..ad4a50fb 100644
--- a/src/NN/CellList/CellNNIterator.hpp
+++ b/src/NN/CellList/CellNNIterator.hpp
@@ -163,7 +163,7 @@ public:
  * \tparam impl implementation specific options NO_CHECK do not do check on access, SAFE do check on access
  *
  */
-template<unsigned int dim, typename Cell,int NNc_size, typename vector_pos_type, unsigned int impl>
+template<unsigned int dim, typename Cell, typename vector_pos_type,int NNc_size, unsigned int impl>
 class CellNNIteratorSym : public CellNNIterator<dim,Cell,NNc_size,impl>
 {
 	//! index of the particle p
@@ -226,7 +226,7 @@ public:
 	 * \return itself
 	 *
 	 */
-	inline CellNNIteratorSym<dim,Cell,NNc_size,vector_pos_type,impl> & operator++()
+	inline CellNNIteratorSym<dim,Cell,vector_pos_type,NNc_size,impl> & operator++()
 	{
 		this->start_id++;
 
@@ -252,16 +252,17 @@ public:
  * \tparam impl implementation specific options NO_CHECK do not do check on access, SAFE do check on access
  *
  */
-template<unsigned int dim, typename Cell,int NNc_size, unsigned int impl> class CellNNIteratorSymMP : public CellNNIterator<dim,Cell,NNc_size,impl>
+template<unsigned int dim, typename Cell, typename vector_pos_type , int NNc_size, unsigned int impl>
+class CellNNIteratorSymMP : public CellNNIterator<dim,Cell,NNc_size,impl>
 {
 	//! index of the particle p
 	size_t p;
 
 	//! Phase vector for particle p
-	const openfpm::vector<Point<dim,typename Cell::stype>> & v_p1;
+	const vector_pos_type & v_p1;
 
 	//! Phase vector for particle q
-	const openfpm::vector<Point<dim,typename Cell::stype>> & v_p2;
+	const vector_pos_type & v_p2;
 
 	/*! Select the next valid element
 	 *
@@ -309,8 +310,8 @@ public:
 			                   size_t p,
 							   const NNc_array<dim,NNc_size> &NNc,
 							   Cell & cl,
-							   const openfpm::vector<Point<dim,typename Cell::stype>> & v_p1,
-							   const openfpm::vector<Point<dim,typename Cell::stype>> & v_p2)
+							   const vector_pos_type & v_p1,
+							   const vector_pos_type & v_p2)
 	:CellNNIterator<dim,Cell,NNc_size,impl>(cell,NNc,cl),p(p),v_p1(v_p1),v_p2(v_p2)
 	{
 		selectValid();
@@ -322,7 +323,7 @@ public:
 	 * \return itself
 	 *
 	 */
-	inline CellNNIteratorSymMP<dim,Cell,NNc_size,impl> & operator++()
+	inline CellNNIteratorSymMP<dim,Cell,vector_pos_type,NNc_size,impl> & operator++()
 	{
 		this->start_id++;
 
diff --git a/src/NN/CellList/CellNNIteratorRuntime.hpp b/src/NN/CellList/CellNNIteratorRuntime.hpp
index e212c120..3ded1d21 100644
--- a/src/NN/CellList/CellNNIteratorRuntime.hpp
+++ b/src/NN/CellList/CellNNIteratorRuntime.hpp
@@ -158,7 +158,7 @@ public:
  *
  */
 template<unsigned int dim, typename Cell,typename vector_pos_type, unsigned int impl>
-class CellNNIteratorSym<dim,Cell,RUNTIME,vector_pos_type,impl> : public CellNNIterator<dim,Cell,RUNTIME,impl>
+class CellNNIteratorSym<dim,Cell,vector_pos_type,RUNTIME,impl> : public CellNNIterator<dim,Cell,RUNTIME,impl>
 {
 	//! index of the particle p
 	size_t p;
@@ -228,7 +228,7 @@ public:
 	 * \return itself
 	 *
 	 */
-	inline CellNNIteratorSym<dim,Cell,RUNTIME,vector_pos_type,impl> & operator++()
+	inline CellNNIteratorSym<dim,Cell,vector_pos_type,RUNTIME,impl> & operator++()
 	{
 		this->start_id++;
 
diff --git a/src/NN/CellList/cuda/Cuda_cell_list_util_func.hpp b/src/NN/CellList/cuda/Cuda_cell_list_util_func.hpp
index 31dd0d41..955e837f 100644
--- a/src/NN/CellList/cuda/Cuda_cell_list_util_func.hpp
+++ b/src/NN/CellList/cuda/Cuda_cell_list_util_func.hpp
@@ -80,7 +80,7 @@ struct cid_<2,cnt_type,ids_type,transform>
 		return e[0] + div_c[0] * e[1];
 	}
 
-	static inline __device__ __host__ cnt_type get_cid(const openfpm::array<ids_type,2,cnt_type> & div_c, const grid_key_dx<2,cnt_type> & e)
+	static inline __device__ __host__ cnt_type get_cid(const openfpm::array<ids_type,2,cnt_type> & div_c, const grid_key_dx<2,ids_type> & e)
 	{
 		return e.get(0) + div_c[0] * e.get(1);
 	}
diff --git a/src/NN/VerletList/VerletListFast.hpp b/src/NN/VerletList/VerletListFast.hpp
index 540a3b06..3294d2e0 100644
--- a/src/NN/VerletList/VerletListFast.hpp
+++ b/src/NN/VerletList/VerletListFast.hpp
@@ -345,7 +345,7 @@ private:
 	{
 		if (opt == VL_CRS_SYMMETRIC)
 		{
-			create_<CellNNIteratorSym<dim,CellListImpl,RUNTIME,vector_pos_type,NO_CHECK>,VL_CRS_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
+			create_<CellNNIteratorSym<dim,CellListImpl,vector_pos_type,RUNTIME,NO_CHECK>,VL_CRS_SYMMETRIC>(pos,pos2,dom,anom,r_cut,g_m,cl,opt);
 		}
 		else if (opt == VL_SYMMETRIC)
 		{
diff --git a/src/Space/Shape/HyperCube.hpp b/src/Space/Shape/HyperCube.hpp
index 18b4baa0..2b3fb9b4 100644
--- a/src/Space/Shape/HyperCube.hpp
+++ b/src/Space/Shape/HyperCube.hpp
@@ -402,7 +402,10 @@ public:
 				val = pos_n_zero[i] - pos_n_zero[i+1] - 1;
 			}
 			else
+			{
+				/* coverty[uninit_use] */
 				val = pos_n_zero[i];
+			}
 
 			for (long int j = 0 ; j < (long int)val; j++)
 			{
diff --git a/src/Space/Shape/Point.hpp b/src/Space/Shape/Point.hpp
index 6cd9aeae..7d76af7e 100644
--- a/src/Space/Shape/Point.hpp
+++ b/src/Space/Shape/Point.hpp
@@ -395,6 +395,7 @@ template<unsigned int dim ,typename T> class Point
 
 		for (size_t i = 0 ; i < dim - 1 ; i++)
 		{
+			/* coverty[dead_error_line] */
 			str += std::to_string(static_cast<double>(get(i))) + " ";
 		}
 		str += std::to_string(static_cast<double>(get(dim-1)));
diff --git a/src/util/compute_optimal_device_grid.hpp b/src/util/compute_optimal_device_grid.hpp
index 96cfa2fd..05b9ec2f 100644
--- a/src/util/compute_optimal_device_grid.hpp
+++ b/src/util/compute_optimal_device_grid.hpp
@@ -166,6 +166,7 @@ void calculate_optimal_device_grid(device_grid<dim> & dg,
 			{dg.grids.z *= z[jz];}
 
 			for (size_t k = 3 ; k < dim ; k++)
+			/* coverty[dead_error_line] */
 			{dg.grids.z *= sz[k];}
 
 			return;
@@ -227,6 +228,7 @@ void calculate_optimal_device_grid(device_grid<dim> & dg,
 			dg.threads.y *= best_fact;
 			dg.grids.y /= best_fact;
 		}
+		/* coverty[dead_error_line] */
 		else if (k_best == 2)
 		{
 			dg.threads.z *= best_fact;
-- 
GitLab