Commit 0bdb91c6 authored by Michael Kuron's avatar Michael Kuron 💡

Fix remaining clang-tidy warnings

parent 26762675
Pipeline #1522 passed with stages
in 16 minutes and 17 seconds
......@@ -33,12 +33,12 @@ maxset:
paths:
- build/
#clang-static-analysis:
# stage: build
# image: espressomd/espresso-ubuntu-clang-cuda:latest
# script:
# - export myconfig=maxset with_coverage=false with_static_analysis=true
# - bash maintainer/cuda_build.sh
clang-static-analysis:
stage: build
image: espressomd/espresso-ubuntu-clang-cuda:latest
script:
- export myconfig=maxset with_coverage=false with_static_analysis=true
- bash maintainer/cuda_build.sh
clang:
stage: build
......
......@@ -349,7 +349,7 @@ if( WITH_CLANG_TIDY )
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=*,-clang-analyzer-alpha.*,-misc-unused-*,-google-*,-llvm-*,-modernize-*,-readability-*,-cppcoreguidelines-*,-clang-analyzer-deadcode*,-cert-*,-clang-analyzer-core.NullDereference,-clang-analyzer-core.DivideZero,-misc-misplaced-widening-cast,-misc-macro-parentheses,-clang-analyzer-security.FloatLoopCounter" "-warnings-as-errors=*")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=*,-clang-analyzer-alpha.*,-misc-unused-*,-google-*,-llvm-*,-modernize-*,-readability-*,-cppcoreguidelines-*,-clang-analyzer-deadcode*,-cert-*,-clang-analyzer-core.NullDereference,-clang-analyzer-core.DivideZero,-misc-misplaced-widening-cast,-misc-macro-parentheses,-clang-analyzer-security.FloatLoopCounter,-clang-analyzer-optin.mpi.MPI-Checker" "-warnings-as-errors=*")
endif()
endif()
......
......@@ -612,19 +612,19 @@ double maxwell_velocitiesC(int part_id, int N_T) {
}
int collectBonds(PartCfg & partCfg, int mode, int part_id, int N_P, int MPC, int type_bond,
int **bond_out, int ***bonds_out) {
int i, j, k, ii, size, *bond = nullptr, **bonds = nullptr;
std::vector<int> bond, std::vector<std::vector<int>> bonds) {
int i, j, k, ii, size;
partCfg.update_bonds();
if (mode == 1) {
/* Find all the bonds leading to and from the ending monomers of the chains.
*/
bond = (int *)Utils::malloc(2 * N_P * sizeof(int));
bonds = (int **)Utils::malloc(2 * N_P * sizeof(int *));
bond.resize(2 * N_P);
bonds.resize(2 * N_P);
for (i = 0; i < 2 * N_P; i++) {
bond[i] = 0;
bonds[i] = (int *)Utils::malloc(1 * sizeof(int));
bonds[i].resize(1);
}
for (k = part_id; k < N_P * MPC + part_id; k++) {
i = 0;
......@@ -637,15 +637,13 @@ int collectBonds(PartCfg & partCfg, int mode, int part_id, int N_P, int MPC, int
ii = partCfg[k].p.identity % MPC
? 2 * (partCfg[k].p.identity + 1) / MPC - 1
: 2 * partCfg[k].p.identity / MPC;
bonds[i] =
Utils::realloc(bonds[i], (bond[i] + 1) * sizeof(int));
bonds[i].resize(bond[i] + 1) ;
bonds[ii][bond[ii]++] = partCfg[k].bl.e[i];
} else if ((partCfg[k].bl.e[i] % MPC == 0) ||
((partCfg[k].bl.e[i] + 1) % MPC == 0)) {
ii = partCfg[k].bl.e[i] % MPC ? 2 * (partCfg[k].bl.e[i] + 1) / MPC - 1
: 2 * partCfg[k].bl.e[i] / MPC;
bonds[i] =
Utils::realloc(bonds[i], (bond[i] + 1) * sizeof(int));
bonds[i].resize(bond[i] + 1);
bonds[ii][bond[ii]++] = partCfg[k].p.identity;
}
i++;
......@@ -663,11 +661,11 @@ int collectBonds(PartCfg & partCfg, int mode, int part_id, int N_P, int MPC, int
});
} else if (mode == 2) {
/* Find all the bonds leading to and from each monomer. */
bond = (int *)Utils::malloc(N_P * MPC * sizeof(int));
bonds = (int **)Utils::malloc(N_P * MPC * sizeof(int *));
bond.resize(N_P * MPC);
bonds.resize(N_P * MPC);
for (i = 0; i < N_P * MPC + part_id; i++) {
bond[i] = 0;
bonds[i] = (int *)Utils::malloc(1 * sizeof(int));
bonds[i].resize(1);
}
for (k = part_id; k < N_P * MPC + part_id; k++) {
i = 0;
......@@ -676,11 +674,9 @@ int collectBonds(PartCfg & partCfg, int mode, int part_id, int N_P, int MPC, int
if (partCfg[k].bl.e[i++] == type_bond) {
for (j = 0; j < size; j++) {
ii = partCfg[k].bl.e[i];
bonds[k] =
Utils::realloc(bonds[k], (bond[k] + 1) * sizeof(int));
bonds[k].resize(bond[k] + 1);
bonds[k][bond[k]++] = ii;
bonds[ii] =
Utils::realloc(bonds[ii], (bond[ii] + 1) * sizeof(int));
bonds[ii].resize(bond[ii] + 1);
bonds[ii][bond[ii]++] = k;
i++;
}
......@@ -701,18 +697,17 @@ int collectBonds(PartCfg & partCfg, int mode, int part_id, int N_P, int MPC, int
return (-2);
}
*bond_out = bond;
*bonds_out = bonds;
return (0);
}
int crosslinkC(PartCfg & partCfg, int N_P, int MPC, int part_id, double r_catch, int link_dist,
int chain_dist, int type_bond, int max_try) {
int i, j, k, ii, size, bondN[2], *bond, **bonds, *link, **links, *cross,
crossL;
int i, j, k, ii, size, bondN[2], crossL;
std::vector<int> bond;
std::vector<std::vector<int>> bonds;
/* Find all the bonds leading to and from each monomer. */
if (collectBonds(partCfg, 2, part_id, N_P, MPC, type_bond, &bond, &bonds))
if (collectBonds(partCfg, 2, part_id, N_P, MPC, type_bond, bond, bonds))
return (-2);
POLY_TRACE(for (i = 0; i < N_P * MPC + part_id; i++) {
printf("%d:\t", i);
......@@ -724,16 +719,15 @@ int crosslinkC(PartCfg & partCfg, int N_P, int MPC, int part_id, double r_catch,
/* Find all possible binding partners in the neighbourhood of the unconnected
* ending monomers. */
link = (int *)Utils::malloc(2 * N_P * sizeof(int));
links = (int **)Utils::malloc(2 * N_P * sizeof(int *));
std::vector<int> link(2 * N_P);
std::vector<std::vector<int>> links(2 * N_P);
for (i = 0; i < N_P; i++) {
for (k = 0; k < 2; k++) {
if (bond[i * MPC + k * (MPC - 1)] == 1) {
links[2 * i + k] = (int *)Utils::malloc(n_part * sizeof(int));
links[2 * i + k].resize(n_part);
link[2 * i + k] = mindist3(partCfg,i * MPC + k * (MPC - 1) + part_id, r_catch,
links[2 * i + k]);
links[2 * i + k] = Utils::realloc(links[2 * i + k],
link[2 * i + k] * sizeof(int));
links[2 * i + k].data());
links[2 * i + k].resize(link[2 * i + k]);
} else if (bond[i * MPC + k * (MPC - 1)] == 2)
link[2 * i + k] = -1; /* Note that links[2*i+k] will not be malloc()ed
now (taken care of at end)!!! */
......@@ -772,8 +766,7 @@ int crosslinkC(PartCfg & partCfg, int N_P, int MPC, int part_id, double r_catch,
links[2 * i + k][j]; /* no ends accepted */
}
link[2 * i + k] = size;
links[2 * i + k] = Utils::realloc(links[2 * i + k],
link[2 * i + k] * sizeof(int));
links[2 * i + k].resize(link[2 * i + k]);
}
POLY_TRACE(printf("%d: ", ii); for (j = 0; j < link[2 * i + k]; j++)
printf("%d ", links[2 * i + k][j]);
......@@ -783,7 +776,7 @@ int crosslinkC(PartCfg & partCfg, int N_P, int MPC, int part_id, double r_catch,
/* Randomly choose a partner (if not available -> '-1') for each polymer
* chain's end if it's not already been crosslinked (-> '-2'). */
cross = (int *)Utils::malloc(2 * N_P * sizeof(int));
std::vector<int> cross(2 * N_P);
crossL = 0;
for (i = 0; i < 2 * N_P; i++)
if (link[i] > 0) {
......@@ -897,20 +890,7 @@ int crosslinkC(PartCfg & partCfg, int N_P, int MPC, int part_id, double r_catch,
ES_ERROR)
return (-3);
}
free(bonds[2 * i]);
if (link[2 * i] >= 0)
free(links[2 * i]); /* else crash(); because links[2*i] has never been
malloc()ed then */
free(bonds[2 * i + 1]);
if (link[2 * i + 1] >= 0)
free(links[2 * i + 1]); /* else crash(); because links[2*i+1] has never
been malloc()ed then */
}
free(bond);
free(bonds);
free(link);
free(links);
free(cross);
POLY_TRACE(printf("Created %d new bonds; now %d ends are crosslinked!\n",
size, crossL));
return (crossL);
......
......@@ -169,7 +169,7 @@ double maxwell_velocitiesC(int part_id, int N_T);
all the bonds leading to and from each monomer (mode == 2).
@return Returns '0' upon success, '-2' otherwise. */
int collectBonds(PartCfg &, int mode, int part_id, int N_P, int MPC, int type_bond,
int **bond_out, int ***bonds_out);
std::vector<int> bond, std::vector<std::vector<int>> bonds);
/** C implementation of 'crosslink \<N_P\> \<MPC\> [options]',
@param N_P = number of polymer chains
......
......@@ -537,11 +537,7 @@ int distribute_tensors(DoubleList *TensorInBin, double *force, int bins[3], doub
double entry[3], exit[3]; /* the positions at which the line enters and exits the cube */
int startx, endx; /* x-bins in which the line starts and ends in */
int occupiedxbins; /* number of x-bins occuped by the line */
int *starty; /* y-bins in which the line starts in for each x-bin. This array has dimension occupiedxbins+1. */
int totoccupiedybins; /* total number of y-bins through which the line passes */
int *occupiedybins; /* number of occupied y-bins for each x-bin */
int *occupiedzbins; /* number of occupied z-bins for each y-bin */
int *startz; /* z-bins in which the line starts in for each y_bin. This array has dimension totaloccupiedybins. */
int xbin, ybin, zbin; /* counters to keep track of bins x_bin goes from 0 to x_bins-1, y_bins from 0 to y_bins-1, z_bins from 0 to Z-bins-1 */
int i ,k, l;
int counter; /* keeps track of where we are in the startz array */
......@@ -613,8 +609,8 @@ int distribute_tensors(DoubleList *TensorInBin, double *force, int bins[3], doub
PTENSOR_TRACE(fprintf(stderr,"%d: distribute_tensors: x goes from %d to %d\n",this_node,startx, endx);)
/* Initialise starty array */
starty = (int *)Utils::malloc(sizeof(int)*(occupiedxbins+1));
occupiedybins = (int *)Utils::malloc(sizeof(int)*occupiedxbins);
std::vector<int>starty(occupiedxbins+1);
std::vector<int> occupiedybins(occupiedxbins);
/* find in which y-bins the line starts and stops for each x-bin */
/* in xbin the line starts in y-bin number starty[xbin-startx] and ends in starty[xbin-startx+1] */
......@@ -641,8 +637,8 @@ int distribute_tensors(DoubleList *TensorInBin, double *force, int bins[3], doub
}
/* Initialise startz array */
occupiedzbins = (int *)Utils::malloc(sizeof(int)*totoccupiedybins);
startz = (int *)Utils::malloc(sizeof(int)*(totoccupiedybins+1));
std::vector<int> occupiedzbins(totoccupiedybins);
std::vector<int> startz(totoccupiedybins+1);
/* find in which z-bins the line starts and stops for each y-bin*/
counter = 0;
if (facein == 2) {
......@@ -774,10 +770,6 @@ int distribute_tensors(DoubleList *TensorInBin, double *force, int bins[3], doub
runtimeErrorMsg() << this_node << ": analyze stress_profile: bug in distribute tensor code - calclength is " << calclength << " and length is " << length;
return 0;
}
free(occupiedzbins);
free(occupiedybins);
free(starty);
free(startz);
}
return 1;
}
......@@ -977,13 +969,13 @@ int local_stress_tensor_calc(DoubleList *TensorInBin, int bins[3],
auto p2 = local_particles[p.bl.e[j++]];
double dx[3];
get_mi_vector(dx, p.r.p, p2->r.p);
double force[3];
calc_bonded_force(&p, p2, iaparams, &j, dx, force);
std::array<double,3> force;
calc_bonded_force(&p, p2, iaparams, &j, dx, force.data());
PTENSOR_TRACE(
fprintf(stderr, "%d: Bonded to particle %d with force %f %f %f\n",
this_node, p2->p.identity, force[0], force[1], force[2]));
if ((pow(force[0], 2) + pow(force[1], 2) + pow(force[2], 2)) > 0) {
if (distribute_tensors(TensorInBin, force, bins, range_start, range,
if (distribute_tensors(TensorInBin, force.data(), bins, range_start, range,
p.r.p, p2->r.p) != 1)
return 0;
}
......
......@@ -62,19 +62,19 @@ void ReactionEnsemble::add_reaction(double equilibrium_constant, std::vector<int
new_reaction->len_reactant_types=len_reactant_types;
int* reactant_coefficients = (int*) malloc(len_reactant_types * sizeof(int));
int* reactant_coefficients = len_reactant_types == 0 ? nullptr : (int*) malloc(len_reactant_types * sizeof(int));
for(int i=0; i< len_reactant_types; i++)
reactant_coefficients[i]=_reactant_coefficients[i];
new_reaction->reactant_coefficients=reactant_coefficients;
int* product_types = (int *)malloc(len_product_types * sizeof(int));
int* product_types = (int *)calloc(len_product_types, sizeof(int));
for(int i=0; i< len_product_types; i++)
product_types[i]=_product_types[i];
new_reaction->product_types=product_types;
new_reaction->len_product_types=len_product_types;
int* product_coefficients = (int *)malloc(len_product_types * sizeof(int));
int* product_coefficients = len_product_types == 0 ? nullptr : (int *)malloc(len_product_types * sizeof(int));
for(int i=0; i< len_product_types; i++)
product_coefficients[i]=_product_coefficients[i];
new_reaction->product_coefficients=product_coefficients;
......@@ -459,7 +459,7 @@ int ReactionEnsemble::update_type_index(int* reactant_types, int len_reactant_ty
if(len_reactant_types>0)
m_current_reaction_system.type_index[0]=reactant_types[0];
else
m_current_reaction_system.type_index[0]=product_types[0];
m_current_reaction_system.type_index[0]=product_types[0]; // NOLINT
m_current_reaction_system.nr_different_types=1;
status_gc_init=init_type_array(m_current_reaction_system.type_index[0]); //make types known in espresso
}
......@@ -891,7 +891,7 @@ void ReactionEnsemble::add_new_CV_degree_of_association(int associated_type, dou
/**
* Adds a new collective variable (CV) of the type potential energy to the Wang-Landau sampling
*/
void ReactionEnsemble::add_new_CV_potential_energy(std::string filename, double delta_CV){
void ReactionEnsemble::add_new_CV_potential_energy(const std::string & filename, double delta_CV){
collective_variable* new_collective_variable=(collective_variable*) calloc(1,sizeof(collective_variable));
new_collective_variable->energy_boundaries_filename=strdup(filename.c_str());
new_collective_variable->delta_CV=delta_CV;
......@@ -919,7 +919,7 @@ int ReactionEnsemble::get_flattened_index_wang_landau(double* current_state, dou
if(collective_variable_i==m_current_wang_landau_system.nr_collective_variables-1 && m_current_wang_landau_system.do_energy_reweighting==true) //for energy collective variable (simple truncating conversion desired)
individual_indices[collective_variable_i]=(int) ((current_state[collective_variable_i]-collective_variables_minimum_values[collective_variable_i])/delta_collective_variables_values[collective_variable_i]);
else //for degree of association collective variables (rounding conversion desired)
individual_indices[collective_variable_i]=(int) ((current_state[collective_variable_i]-collective_variables_minimum_values[collective_variable_i])/delta_collective_variables_values[collective_variable_i]+0.5);
individual_indices[collective_variable_i]= std::lround((current_state[collective_variable_i]-collective_variables_minimum_values[collective_variable_i])/delta_collective_variables_values[collective_variable_i]);
if(individual_indices[collective_variable_i]<0 or individual_indices[collective_variable_i]>=nr_subindices_of_collective_variable[collective_variable_i]) // sanity check
return -10;
}
......@@ -1061,10 +1061,10 @@ double find_minimum_non_negative_value(double* list, int len){
* Finds the minimum in a double array and returns it.
*/
double find_minimum(double* list, int len){
double minimum =list[0];
double minimum =list[0]; // NOLINT
for (int i=0;i<len;i++){
if(list[i]<minimum)
minimum=list[i];
if(list[i]<minimum) // NOLINT
minimum=list[i]; // NOLINT
}
return minimum;
}
......
......@@ -209,7 +209,7 @@ public:
add_new_CV_degree_of_association(int associated_type, double CV_minimum,
double CV_maximum,
std::vector<int> _corresponding_acid_types);
void add_new_CV_potential_energy(std::string filename, double delta_CV);
void add_new_CV_potential_energy(const std::string & filename, double delta_CV);
int do_reaction_wang_landau();
int update_maximum_and_minimum_energies_at_current_state(); // use for
// preliminary
......
......@@ -41,7 +41,7 @@ static void add_lj_internal(std::set<PdbParser::itp_atomtype, PdbParser::itp_ato
continue;
if(only_diagonal && (it->espresso_id != jt->espresso_id))
continue;
const double epsilon_ij = sqrt(it->epsilon * jt->epsilon);
const double epsilon_ij = sqrtf(it->epsilon * jt->epsilon);
const double sigma_ij = 0.5*(10.*it->sigma+10.*jt->sigma);
const double cutoff_ij = rel_cutoff*sigma_ij;
const double shift_ij = -pow(sigma_ij/cutoff_ij,12) - pow(sigma_ij/cutoff_ij,6);
......
......@@ -661,6 +661,7 @@ void calc_structurefactor(PartCfg &partCfg, int *p_types, int n_types,
order2 = order * order;
*_ff = ff = Utils::realloc(ff, 2 * order2 * sizeof(double));
ff[2 * order2] = 0;
twoPI_L = 2 * PI / box_l[0];
if ((n_types < 0) || (n_types > n_particle_types)) {
......@@ -798,8 +799,8 @@ int calc_cylindrical_average(
double binwd_axial = length / bins_axial;
double binwd_radial = radius / bins_radial;
auto center = Vector3d{center_};
auto direction = Vector3d{direction_};
auto center = Vector3d{std::move(center_)};
auto direction = Vector3d{std::move(direction_)};
// Select all particle types if the only entry in types is -1
bool all_types = false;
......
......@@ -682,14 +682,13 @@ void analyze_rdfchain(PartCfg & partCfg, double r_min, double r_max, int r_bins,
double **_f2, double **_f3) {
int i, j, ind, c_i, c_j, mon;
double bin_width, inv_bin_width, factor, r_in, r_out, bin_volume, dist,
chain_mass, *cm = nullptr, *min_d = nullptr, *f1 = nullptr, *f2 = nullptr, *f3 = nullptr;
chain_mass, *f1 = nullptr, *f2 = nullptr, *f3 = nullptr;
*_f1 = f1 = Utils::realloc(f1, r_bins * sizeof(double));
*_f2 = f2 = Utils::realloc(f2, r_bins * sizeof(double));
*_f3 = f3 = Utils::realloc(f3, r_bins * sizeof(double));
cm = Utils::realloc(cm, (chain_n_chains * 3) * sizeof(double));
min_d = Utils::realloc(
min_d, (chain_n_chains * chain_n_chains) * sizeof(double));
std::vector<double> cm(chain_n_chains * 3);
std::vector<double> min_d(chain_n_chains * chain_n_chains);
for (i = 0; i < r_bins; i++) {
f1[i] = f2[i] = f3[i] = 0.0;
}
......
......@@ -143,7 +143,7 @@ void lb_calc_densprof(double *result, int *params) {
int index, dir[3], grid[3];
int newroot=0, subrank, involved=0;
double *profile;
double *profile = nullptr;
MPI_Comm slice_comm;
MPI_Status status;
......@@ -170,9 +170,6 @@ void lb_calc_densprof(double *result, int *params) {
MPI_Comm_split(comm_cart, involved, this_node, &slice_comm);
MPI_Comm_rank(slice_comm, &subrank);
if (this_node == newroot)
result = Utils::realloc(result,box_l[pdir]/lblattice.agrid[pdir]*sizeof(double));
if (involved) {
profile = (double*) Utils::malloc(lblattice.grid[pdir]*sizeof(double));
......@@ -206,7 +203,6 @@ void lb_calc_densprof(double *result, int *params) {
if (newroot != 0) {
if (this_node == newroot) {
MPI_Send(result, lblattice.grid[pdir]*node_grid[pdir], MPI_DOUBLE, 0, REQ_DENSPROF, comm_cart);
free(result);
}
if (this_node == 0) {
MPI_Recv(result, lblattice.grid[pdir]*node_grid[pdir], MPI_DOUBLE, newroot, REQ_DENSPROF, comm_cart, &status);
......@@ -256,9 +252,6 @@ void lb_calc_velprof(double *result, int *params) {
MPI_Comm_split(comm_cart, involved, this_node, &slice_comm);
MPI_Comm_rank(slice_comm, &subrank);
if (this_node == newroot)
result = Utils::realloc(result,box_l[pdir]/lblattice.agrid[pdir]*sizeof(double));
//fprintf(stderr,"%d (%d,%d): result=%p vcomp=%d pdir=%d x1=%d x2=%d involved=%d\n",this_node,subrank,newroot,result,vcomp,pdir,x1,x2,involved);
if (involved) {
......@@ -304,7 +297,6 @@ void lb_calc_velprof(double *result, int *params) {
if (newroot != 0) {
if (this_node == newroot) {
MPI_Send(result, lblattice.grid[pdir]*node_grid[pdir], MPI_DOUBLE, 0, REQ_VELPROF, comm_cart);
free(result);
}
if (this_node == 0) {
//fprintf(stderr,"%d: I'm just here!\n",this_node);
......
......@@ -7,8 +7,9 @@ char *strcat_alloc(char *left, const char *right) {
strncpy(res, right, strlen(right) + 1);
return res;
} else {
char *res = Utils::realloc(left, strlen(left) + strlen(right) + 1);
strncat(res, right, strlen(left) + strlen(right) + 1);
size_t newlen = strlen(left) + strlen(right) + 1;
char *res = Utils::realloc(left, newlen);
strncat(res, right, newlen);
return res;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment