From: Daniel Arndt Date: Thu, 26 Apr 2018 14:40:47 +0000 (+0200) Subject: Fix issues reported by cppcheck X-Git-Tag: v9.0.0-rc1~99^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9d00bca3a9d29aff3e5e06410d5e13b2fb381c1;p=dealii.git Fix issues reported by cppcheck --- diff --git a/source/base/function_lib.cc b/source/base/function_lib.cc index 41d0eedb02..ae9838e149 100644 --- a/source/base/function_lib.cc +++ b/source/base/function_lib.cc @@ -2212,15 +2212,17 @@ namespace Functions { Assert(dim==2, ExcNotImplemented()); AssertDimension(points.size(), values.size()); +#ifndef DEAL_II_HAVE_JN + (void) points; + (void) values; + Assert(false, ExcMessage("The Bessel function jn was not found by CMake.")); +#else for (unsigned int k=0; k(); #endif @@ -2259,6 +2262,9 @@ namespace Functions { Assert(dim==2, ExcNotImplemented()); AssertDimension(points.size(), gradients.size()); +#ifndef DEAL_II_HAVE_JN + Assert(false, ExcMessage("The Bessel function jn was not found by CMake.")); +#else for (unsigned int k=0; k &p = points[k]; @@ -2266,18 +2272,14 @@ namespace Functions const double co = (r==0.) ? 0. : (p(0)-center(0))/r; const double si = (r==0.) ? 0. : (p(1)-center(1))/r; -#ifdef DEAL_II_HAVE_JN const double dJn = (order==0) ? (-jn(1, r*wave_number)) : (.5*(jn(order-1, wave_number*r) -jn(order+1, wave_number*r))); -#else - const double dJn = 0.; - Assert(false, ExcMessage("The Bessel function jn was not found by CMake.")); -#endif Tensor<1,dim> &result = gradients[k]; result[0] = wave_number * co * dJn; result[1] = wave_number * si * dJn; } +#endif } diff --git a/source/base/mpi.cc b/source/base/mpi.cc index 6975286e46..5d0a06e9a2 100644 --- a/source/base/mpi.cc +++ b/source/base/mpi.cc @@ -307,7 +307,7 @@ namespace Utilities "in a program since it initializes the MPI system.")); - int ierr; + int ierr = 0; #ifdef DEAL_II_WITH_MPI // if we have PETSc, we will initialize it and let it handle MPI. // Otherwise, we will do it. diff --git a/source/base/polynomial.cc b/source/base/polynomial.cc index 87aae95d6e..72952d9762 100644 --- a/source/base/polynomial.cc +++ b/source/base/polynomial.cc @@ -1005,8 +1005,7 @@ namespace Polynomials // check: does the information // already exist? if ( (recursive_coefficients.size() < k+1) || - ((recursive_coefficients.size() >= k+1) && - (recursive_coefficients[k].get() == nullptr)) ) + (recursive_coefficients[k].get() == nullptr)) // no, then generate the // respective coefficients { @@ -1040,20 +1039,20 @@ namespace Polynomials // later assign it to the // coefficients array to // make it const - std::vector *c0 = new std::vector(2); - (*c0)[0] = 1.; - (*c0)[1] = -1.; + std::vector c0(2); + c0[0] = 1.; + c0[1] = -1.; - std::vector *c1 = new std::vector(2); - (*c1)[0] = 0.; - (*c1)[1] = 1.; + std::vector c1(2); + c1[0] = 0.; + c1[1] = 1.; // now make these arrays // const recursive_coefficients[0] = - std::unique_ptr >(c0); + std_cxx14::make_unique >(std::move(c0)); recursive_coefficients[1] = - std::unique_ptr >(c1); + std_cxx14::make_unique >(std::move(c1)); } else if (k==2) { @@ -1061,16 +1060,16 @@ namespace Polynomials compute_coefficients(1); coefficients_lock.acquire (); - std::vector *c2 = new std::vector(3); + std::vector c2(3); const double a = 1.; //1./8.; - (*c2)[0] = 0.*a; - (*c2)[1] = -4.*a; - (*c2)[2] = 4.*a; + c2[0] = 0.*a; + c2[1] = -4.*a; + c2[2] = 4.*a; recursive_coefficients[2] = - std::unique_ptr >(c2); + std_cxx14::make_unique >(std::move(c2)); } else { @@ -1086,17 +1085,17 @@ namespace Polynomials compute_coefficients(k-1); coefficients_lock.acquire (); - std::vector *ck = new std::vector(k+1); + std::vector ck (k+1); const double a = 1.; //1./(2.*k); - (*ck)[0] = - a*(*recursive_coefficients[k-1])[0]; + ck[0] = - a*(*recursive_coefficients[k-1])[0]; for (unsigned int i=1; i<=k-1; ++i) - (*ck)[i] = a*( 2.*(*recursive_coefficients[k-1])[i-1] - - (*recursive_coefficients[k-1])[i] ); + ck[i] = a*( 2.*(*recursive_coefficients[k-1])[i-1] + - (*recursive_coefficients[k-1])[i] ); - (*ck)[k] = a*2.*(*recursive_coefficients[k-1])[k-1]; + ck[k] = a*2.*(*recursive_coefficients[k-1])[k-1]; // for even degrees, we need // to add a multiple of // basis fcn phi_2 @@ -1106,15 +1105,15 @@ namespace Polynomials //for (unsigned int i=1; i<=k; i++) // b /= 2.*i; - (*ck)[1] += b*(*recursive_coefficients[2])[1]; - (*ck)[2] += b*(*recursive_coefficients[2])[2]; + ck[1] += b*(*recursive_coefficients[2])[1]; + ck[2] += b*(*recursive_coefficients[2])[2]; } // finally assign the newly // created vector to the // const pointer in the // coefficients array recursive_coefficients[k] = - std::unique_ptr >(ck); + std_cxx14::make_unique >(std::move(ck)); }; }; } diff --git a/source/distributed/grid_refinement.cc b/source/distributed/grid_refinement.cc index 978448b9bb..319d39ee7e 100644 --- a/source/distributed/grid_refinement.cc +++ b/source/distributed/grid_refinement.cc @@ -226,7 +226,7 @@ namespace template number compute_threshold (const dealii::Vector &criteria, - const std::pair global_min_and_max, + const std::pair &global_min_and_max, const unsigned int n_target_cells, MPI_Comm mpi_communicator) { @@ -316,7 +316,7 @@ namespace template number compute_threshold (const dealii::Vector &criteria, - const std::pair global_min_and_max, + const std::pair &global_min_and_max, const double target_error, MPI_Comm mpi_communicator) { diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 6f1e0e244a..d653e0421b 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -519,10 +519,9 @@ namespace typename internal::p4est::types::quadrant &ghost_quadrant, types::subdomain_id ghost_owner) { - int i, child_id; int l = ghost_quadrant.level; - for (i = 0; i < l; i++) + for (int i = 0; i < l; i++) { typename Triangulation::cell_iterator cell (tria, i, dealii_index); if (cell->has_children () == false) @@ -532,7 +531,7 @@ namespace return; } - child_id = internal::p4est::functions::quadrant_ancestor_id (&ghost_quadrant, i + 1); + const int child_id = internal::p4est::functions::quadrant_ancestor_id (&ghost_quadrant, i + 1); dealii_index = cell->child_index(child_id); } @@ -1223,7 +1222,7 @@ namespace * order that p4est will encounter the cells, and they do not contain * ghost cells or artificial cells. */ - PartitionWeights (const std::vector &cell_weights); + explicit PartitionWeights (const std::vector &cell_weights); /** * A callback function that we pass to the p4est data structures when a diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index c260432503..93f5cac25e 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -122,8 +122,7 @@ namespace internal void *) { if (cell->has_children() - || - (!cell->has_children() && !cell->is_artificial())) + || !cell->is_artificial()) cell->update_cell_dof_indices_cache (); }; diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 24954a41fc..8db5169fbb 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -1640,7 +1640,6 @@ void GridIn<2>::read_netcdf (const std::string &filename) #else const unsigned int dim=2; const unsigned int spacedim=2; - const bool output=false; Assert (tria != 0, ExcNoTriangulationSelected()); // this function assumes the TAU // grid format. @@ -1913,7 +1912,6 @@ void GridIn<3>::read_netcdf (const std::string &filename) #else const unsigned int dim=3; const unsigned int spacedim=3; - const bool output=false; Assert (tria != 0, ExcNoTriangulationSelected()); // this function assumes the TAU // grid format. @@ -1926,8 +1924,6 @@ void GridIn<3>::read_netcdf (const std::string &filename) NcDim *elements_dim=nc.get_dim("no_of_elements"); AssertThrow(elements_dim->is_valid(), ExcIO()); const unsigned int n_cells=elements_dim->size(); - if (output) - std::cout << "n_cell=" << n_cells << std::endl; // and n_hexes NcDim *hexes_dim=nc.get_dim("no_of_hexaeders"); AssertThrow(hexes_dim->is_valid(), ExcIO()); @@ -1960,17 +1956,6 @@ void GridIn<3>::read_netcdf (const std::string &filename) for (unsigned int i=0; i=0, ExcIO()); - if (output) - { - std::cout << "vertex_indices:" << std::endl; - for (unsigned int cell=0, v=0; cell::read_netcdf (const std::string &filename) NcDim *vertices_dim=nc.get_dim("no_of_points"); AssertThrow(vertices_dim->is_valid(), ExcIO()); const unsigned int n_vertices=vertices_dim->size(); - if (output) - std::cout << "n_vertices=" << n_vertices << std::endl; NcVar *points_xc=nc.get_var("points_xc"); NcVar *points_yc=nc.get_var("points_yc"); @@ -1998,19 +1981,9 @@ void GridIn<3>::read_netcdf (const std::string &filename) static_cast(n_vertices), ExcIO()); std::vector > point_values( 3, std::vector (n_vertices)); - // we switch y and z - const bool switch_y_z=false; points_xc->get(&*point_values[0].begin(), n_vertices); - if (switch_y_z) - { - points_yc->get(&*point_values[2].begin(), n_vertices); - points_zc->get(&*point_values[1].begin(), n_vertices); - } - else - { - points_yc->get(&*point_values[1].begin(), n_vertices); - points_zc->get(&*point_values[2].begin(), n_vertices); - } + points_yc->get(&*point_values[1].begin(), n_vertices); + points_zc->get(&*point_values[2].begin(), n_vertices); // and fill the vertices std::vector > vertices (n_vertices); @@ -2052,18 +2025,6 @@ void GridIn<3>::read_netcdf (const std::string &filename) std::vector bvertex_indices(n_bquads*vertices_per_quad); bvertex_indices_var->get(&*bvertex_indices.begin(), n_bquads, vertices_per_quad); - if (output) - { - std::cout << "bquads: "; - for (unsigned int i=0; i::vertices_per_face; ++v) - std::cout << bvertex_indices[ - i*GeometryInfo::vertices_per_face+v] << " "; - std::cout << std::endl; - } - } - // next we read // int boundarymarker_of_surfaces( // no_of_surfaceelements) diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index e244e2b21d..58083093c7 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -566,7 +566,7 @@ namespace GridTools class Shift { public: - Shift (const Tensor<1,spacedim> &shift) + explicit Shift (const Tensor<1,spacedim> &shift) : shift(shift) {} @@ -585,7 +585,7 @@ namespace GridTools class Rotate2d { public: - Rotate2d (const double angle) + explicit Rotate2d (const double angle) : angle(angle) {} @@ -633,7 +633,7 @@ namespace GridTools class Scale { public: - Scale (const double factor) + explicit Scale (const double factor) : factor(factor) {} diff --git a/source/grid/manifold_lib.cc b/source/grid/manifold_lib.cc index ab2178a473..5d775c71c1 100644 --- a/source/grid/manifold_lib.cc +++ b/source/grid/manifold_lib.cc @@ -615,7 +615,7 @@ get_new_points (const ArrayView> &surrounding_points, // be good enough. This tolerance was chosen such that the first iteration // for a at least three time refined HyperShell mesh with radii .5 and 1. // doesn't already succeed. - if (max_distance < 2e-2 || spacedim<3) + if (max_distance < 2e-2) { for (unsigned int row=0; row::lines_per_cell; ++line) { - const double my_weight = line%2 ? chart_point[line/2] : 1-chart_point[line/2]; + const double my_weight = (line%2) ? chart_point[line/2] : 1-chart_point[line/2]; const double line_point = chart_point[1-line/2]; // Same manifold or invalid id which will go back to the same diff --git a/source/lac/trilinos_epetra_vector.cc b/source/lac/trilinos_epetra_vector.cc index 47446f04e9..a73927d6b5 100644 --- a/source/lac/trilinos_epetra_vector.cc +++ b/source/lac/trilinos_epetra_vector.cc @@ -145,8 +145,7 @@ namespace LinearAlgebra // Check if the communication pattern already exists and if it can be // reused. if ((source_stored_elements.size() != V.get_stored_elements().size()) || - ((source_stored_elements.size() == V.get_stored_elements().size()) && - (source_stored_elements != V.get_stored_elements()))) + (source_stored_elements != V.get_stored_elements())) { create_epetra_comm_pattern(V.get_stored_elements(), dynamic_cast(vector->Comm()).Comm()); diff --git a/source/matrix_free/task_info.cc b/source/matrix_free/task_info.cc index 97dd3fe79b..8ef9e0b814 100644 --- a/source/matrix_free/task_info.cc +++ b/source/matrix_free/task_info.cc @@ -1413,8 +1413,8 @@ namespace internal Assert(!hp_bool || cell_active_fe_index.size() == n_active_cells, ExcInternalError()); - unsigned int n_macro_cells_before = 0; { + unsigned int n_macro_cells_before = 0; // Create partitioning within partitions. // For each block of cells, this variable saves to which partitions @@ -1426,7 +1426,6 @@ namespace internal partition_row_index.resize(partition+1,0); cell_partition_data.resize(1,0); - unsigned int start_up = 0; unsigned int counter = 0; unsigned int missing_macros; for (unsigned int part=0; part &partition_size, std::vector &partition_color_list) { - const unsigned int n_macro_cells = *(cell_partition_data.end()-2); - std::vector neighbor_list; - std::vector neighbor_neighbor_list; std::vector cell_color(n_blocks, n_macro_cells); std::vector color_finder;