From: Roland Schulz Date: Sat, 19 Apr 2014 08:51:39 +0000 (-0400) Subject: Fix cppcheck 1.64 warnings X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=e7ab47d190a00a75e5f6fa1531a49c9959c21fc3;p=alexxy%2Fgromacs.git Fix cppcheck 1.64 warnings Related to #1487 Change-Id: I223289d71e0dfc426f382d1bcb53b3509202779f --- diff --git a/src/external/tng_io/src/lib/md5.c b/src/external/tng_io/src/lib/md5.c index ea8bb37b5e..0ab0367e78 100644 --- a/src/external/tng_io/src/lib/md5.c +++ b/src/external/tng_io/src/lib/md5.c @@ -165,7 +165,6 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) #else /* Define storage for little-endian or both types of CPUs. */ md5_word_t xbuf[16]; - /* cppcheck-suppress unassignedVariable */ const md5_word_t *X; #endif diff --git a/src/gromacs/essentialdynamics/edsam.c b/src/gromacs/essentialdynamics/edsam.c index d2885ea278..1498500cce 100644 --- a/src/gromacs/essentialdynamics/edsam.c +++ b/src/gromacs/essentialdynamics/edsam.c @@ -1796,6 +1796,7 @@ static int read_edi_file(const char *fn, t_edpar *edi, int nr_mdatoms) /* Keep the curr_edi pointer for the case that the next group is empty: */ last_edi = curr_edi; /* Let's prepare to read in the next edi data set: */ + /* cppcheck-suppress uninitvar Fixed in cppcheck 1.65 */ curr_edi = edi_read; } if (edi_nr == 0) diff --git a/src/gromacs/fileio/gmxfio_asc.c b/src/gromacs/fileio/gmxfio_asc.c index e44dffed2c..50756f6c7c 100644 --- a/src/gromacs/fileio/gmxfio_asc.c +++ b/src/gromacs/fileio/gmxfio_asc.c @@ -104,7 +104,7 @@ static void encode_string(int maxlen, char dst[], const char src[]) { int i; - for (i = 0; (src[i] != '\0') && (i < maxlen - 1); i++) + for (i = 0; (i < maxlen - 1) && (src[i] != '\0'); i++) { if ((src[i] == ' ') || (src[i] == '\t')) { @@ -127,7 +127,7 @@ static void decode_string(int maxlen, char dst[], const char src[]) { int i; - for (i = 0; (src[i] != '\0') && (i < maxlen - 1); i++) + for (i = 0; (i < maxlen - 1) && (src[i] != '\0'); i++) { if (src[i] == '_') { diff --git a/src/gromacs/fileio/md5.c b/src/gromacs/fileio/md5.c index ca27dbb75a..e6a608ebf3 100644 --- a/src/gromacs/fileio/md5.c +++ b/src/gromacs/fileio/md5.c @@ -184,7 +184,6 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) #else /* Define storage for little-endian or both types of CPUs. */ md5_word_t xbuf[16]; - /* cppcheck-suppress unassignedVariable */ const md5_word_t *X; #endif diff --git a/src/gromacs/fileio/trajectory_writing.c b/src/gromacs/fileio/trajectory_writing.c index f19020867d..5a55f88331 100644 --- a/src/gromacs/fileio/trajectory_writing.c +++ b/src/gromacs/fileio/trajectory_writing.c @@ -147,7 +147,6 @@ do_md_trajectory_writing(FILE *fplog, if (bCPT) { (*nchkpt)++; - bCPT = FALSE; } debug_gmx(); if (bLastStep && step_rel == ir->nsteps && diff --git a/src/gromacs/fileio/xdrd.c b/src/gromacs/fileio/xdrd.c index e05cbdd4fd..682e68cdd8 100644 --- a/src/gromacs/fileio/xdrd.c +++ b/src/gromacs/fileio/xdrd.c @@ -109,7 +109,7 @@ int xdr_int64(XDR *xdrs, gmx_int64_t *i) imaj = (int)imaj64; imin = (int)imin64; ret = xdr_int(xdrs, &imaj); - ret = xdr_int(xdrs, &imin); + ret |= xdr_int(xdrs, &imin); *i = (((gmx_int64_t)imaj << 32) | ((gmx_int64_t)imin & two_p32_m1)); diff --git a/src/gromacs/gmxana/edittop.c b/src/gromacs/gmxana/edittop.c index 50dd7731c7..9295f8c70e 100644 --- a/src/gromacs/gmxana/edittop.c +++ b/src/gromacs/gmxana/edittop.c @@ -111,6 +111,7 @@ static void delete_from_interactions(t_idef *idef, int inr) idef->il[i].iatoms[j] = niatoms[j]; } idef->il[i].nr = nnr; + /* cppcheck-suppress uninitvar Fixed in cppcheck 1.65 */ sfree(niatoms); } } diff --git a/src/gromacs/gmxana/gmx_bar.c b/src/gromacs/gmxana/gmx_bar.c index 1888159574..e71ec7e35e 100644 --- a/src/gromacs/gmxana/gmx_bar.c +++ b/src/gromacs/gmxana/gmx_bar.c @@ -356,7 +356,7 @@ static void lambda_vec_print(const lambda_vec_t *lv, char *str, gmx_bool named) str += sprintf(str, "dH/dl"); if (strlen(lv->lc->names[lv->dhdl]) > 0) { - str += sprintf(str, " (%s)", lv->lc->names[lv->dhdl]); + sprintf(str, " (%s)", lv->lc->names[lv->dhdl]); } } } diff --git a/src/gromacs/gmxana/gmx_confrms.c b/src/gromacs/gmxana/gmx_confrms.c index 37f90b9d08..82bc68263b 100644 --- a/src/gromacs/gmxana/gmx_confrms.c +++ b/src/gromacs/gmxana/gmx_confrms.c @@ -176,7 +176,7 @@ int find_next_match_atoms_in_res(int *i1, atom_id index1[], { if (debug) { - fprintf(debug, "{%d %d}", *i1+bFW ? dx : dy, *i2+bFW ? dy : dx ); + fprintf(debug, "{%d %d}", *i1 + (bFW ? dx : dy), *i2 + (bFW ? dy : dx) ); } if (bFW) { diff --git a/src/gromacs/gmxana/gmx_current.c b/src/gromacs/gmxana/gmx_current.c index 19bd0a0bea..171a7a91c2 100644 --- a/src/gromacs/gmxana/gmx_current.c +++ b/src/gromacs/gmxana/gmx_current.c @@ -36,6 +36,7 @@ #include #endif +#include #include #include "gromacs/commandline/pargs.h" @@ -471,7 +472,7 @@ static void dielectric(FILE *fmj, FILE *fmd, FILE *outf, FILE *fcur, FILE *mcor, xshfr[i] = 0.0; } } - + assert(time != NULL); if (nfr == 0) diff --git a/src/gromacs/gmxana/gmx_do_dssp.c b/src/gromacs/gmxana/gmx_do_dssp.c index d3fdbb9952..f90e2f0bf5 100644 --- a/src/gromacs/gmxana/gmx_do_dssp.c +++ b/src/gromacs/gmxana/gmx_do_dssp.c @@ -495,7 +495,7 @@ int gmx_do_dssp(int argc, char *argv[]) gmx_bool *bPhbres, bDoAccSurf; real t; int i, j, natoms, nframe = 0; - matrix box; + matrix box = {{0}}; int gnx; char *grpnm, *ss_str; atom_id *index; diff --git a/src/gromacs/gmxana/gmx_eneconv.c b/src/gromacs/gmxana/gmx_eneconv.c index ef58eca114..3e87f0dbd4 100644 --- a/src/gromacs/gmxana/gmx_eneconv.c +++ b/src/gromacs/gmxana/gmx_eneconv.c @@ -583,7 +583,6 @@ int gmx_eneconv(int argc, char *argv[]) nset = 0; timestep = 0.0; snew(fnms, argc); - nfile = 0; lastfilestep = 0; laststep = startstep = 0; diff --git a/src/gromacs/gmxana/gmx_hbond.c b/src/gromacs/gmxana/gmx_hbond.c index 3a86c9780e..0a0b6d88e3 100644 --- a/src/gromacs/gmxana/gmx_hbond.c +++ b/src/gromacs/gmxana/gmx_hbond.c @@ -1183,7 +1183,7 @@ static void add_dh(t_donors *ddd, int id, int ih, int grp, unsigned char *databl { int i; - if (ISDON(datable[id]) || !datable) + if (!datable || ISDON(datable[id])) { if (ddd->dptr[id] == NOTSET) /* New donor */ { @@ -2543,13 +2543,16 @@ static void parallel_print(int *data, int nThreads) static void normalizeACF(real *ct, real *gt, int nhb, int len) { - real ct_fac, gt_fac; + real ct_fac, gt_fac = 0; int i; /* Xu and Berne use the same normalization constant */ ct_fac = 1.0/ct[0]; - gt_fac = (nhb == 0) ? 0 : 1.0/(real)nhb; + if (nhb != 0) + { + gt_fac = 1.0/(real)nhb; + } printf("Normalization for c(t) = %g for gh(t) = %g\n", ct_fac, gt_fac); for (i = 0; i < len; i++) @@ -4617,6 +4620,7 @@ int gmx_hbond(int argc, char *argv[]) { t_matrix mat; int id, ia, hh, x, y; + mat.flags = mat.y0 = 0; if ((nframes > 0) && (hb->nrhb > 0)) { diff --git a/src/gromacs/gmxana/gmx_hydorder.c b/src/gromacs/gmxana/gmx_hydorder.c index c6fb42a8ba..a86c35327e 100644 --- a/src/gromacs/gmxana/gmx_hydorder.c +++ b/src/gromacs/gmxana/gmx_hydorder.c @@ -67,7 +67,7 @@ static void print_types(atom_id index[], atom_id a[], int ngrps, fprintf(stderr, "Using following groups: \n"); for (i = 0; i < ngrps; i++) { - fprintf(stderr, "Groupname: %s First atomname: %s First atomnr %u\n", + fprintf(stderr, "Groupname: %s First atomname: %s First atomnr %d\n", groups[i], *(top->atoms.atomname[a[index[i]]]), a[index[i]]); } fprintf(stderr, "\n"); diff --git a/src/gromacs/gmxana/gmx_make_edi.c b/src/gromacs/gmxana/gmx_make_edi.c index c2b85efcef..bc869d2657 100644 --- a/src/gromacs/gmxana/gmx_make_edi.c +++ b/src/gromacs/gmxana/gmx_make_edi.c @@ -861,7 +861,6 @@ int gmx_make_edi(int argc, char *argv[]) printf("\n"); } - EigvecFile = NULL; EigvecFile = opt2fn("-f", NFILE, fnm); /*read eigenvectors from eigvec.trr*/ diff --git a/src/gromacs/gmxana/gmx_mdmat.c b/src/gromacs/gmxana/gmx_mdmat.c index d11ca0d2f4..c3e046ab9c 100644 --- a/src/gromacs/gmxana/gmx_mdmat.c +++ b/src/gromacs/gmxana/gmx_mdmat.c @@ -223,7 +223,7 @@ int gmx_mdmat(int argc, char *argv[]) int **nmat, **totnmat; real *mean_n; int *tot_n; - matrix box; + matrix box = {{0}}; output_env_t oenv; gmx_rmpbc_t gpbc = NULL; diff --git a/src/gromacs/gmxana/gmx_order.c b/src/gromacs/gmxana/gmx_order.c index 409918c90d..12902c9167 100644 --- a/src/gromacs/gmxana/gmx_order.c +++ b/src/gromacs/gmxana/gmx_order.c @@ -357,7 +357,7 @@ static void print_types(atom_id index[], atom_id a[], int ngrps, fprintf(stderr, "Using following groups: \n"); for (i = 0; i < ngrps; i++) { - fprintf(stderr, "Groupname: %s First atomname: %s First atomnr %u\n", + fprintf(stderr, "Groupname: %s First atomname: %s First atomnr %d\n", groups[i], *(top->atoms.atomname[a[index[i]]]), a[index[i]]); } fprintf(stderr, "\n"); diff --git a/src/gromacs/gmxana/gmx_rms.c b/src/gromacs/gmxana/gmx_rms.c index a059824da8..28cd76faf3 100644 --- a/src/gromacs/gmxana/gmx_rms.c +++ b/src/gromacs/gmxana/gmx_rms.c @@ -230,7 +230,7 @@ int gmx_rms(int argc, char *argv[]) int ePBC; t_iatom *iatom = NULL; - matrix box; + matrix box = {{0}}; rvec *x, *xp, *xm = NULL, **mat_x = NULL, **mat_x2, *mat_x2_j = NULL, vec1, vec2; t_trxstatus *status; diff --git a/src/gromacs/gmxana/gmx_tune_pme.c b/src/gromacs/gmxana/gmx_tune_pme.c index 2e0aeb11a4..dcd7778740 100644 --- a/src/gromacs/gmxana/gmx_tune_pme.c +++ b/src/gromacs/gmxana/gmx_tune_pme.c @@ -532,7 +532,6 @@ static gmx_bool analyze_data( /* Only mention settings if they were modified: */ bRefinedCoul = !gmx_within_tol(info->rcoulomb[k_win], info->rcoulomb[0], GMX_REAL_EPS); - bRefinedCoul = !gmx_within_tol(info->rcoulomb[k_win], info->rcoulomb[0], GMX_REAL_EPS); bRefinedVdW = !gmx_within_tol(info->rvdw[k_win], info->rvdw[0], GMX_REAL_EPS); bRefinedGrid = !(info->nkx[k_win] == info->nkx[0] && info->nky[k_win] == info->nky[0] && diff --git a/src/gromacs/gmxana/gmx_vanhove.c b/src/gromacs/gmxana/gmx_vanhove.c index 934099757d..640d786db9 100644 --- a/src/gromacs/gmxana/gmx_vanhove.c +++ b/src/gromacs/gmxana/gmx_vanhove.c @@ -38,6 +38,7 @@ #include #endif +#include #include #include #include @@ -200,6 +201,7 @@ int gmx_vanhove(int argc, char *argv[]) srenew(sbox, nalloc); srenew(sx, nalloc); } + assert(time != NULL); assert(sbox != NULL); time[nfr] = t; copy_mat(box, sbox[nfr]); diff --git a/src/gromacs/gmxana/gmx_xpm2ps.c b/src/gromacs/gmxana/gmx_xpm2ps.c index 9c3ae9b00d..d230bca60f 100644 --- a/src/gromacs/gmxana/gmx_xpm2ps.c +++ b/src/gromacs/gmxana/gmx_xpm2ps.c @@ -711,11 +711,11 @@ void xpm_mat(const char *outf, int nmat, t_matrix *mat, t_matrix *mat2, sfree(mat[i].map); mat[i].nmap = nmap; mat[i].map = map; - if (mat2 && (strcmp(mat[i].title, mat2[i].title) != 0)) + if (strcmp(mat[i].title, mat2[i].title) != 0) { sprintf(mat[i].title+strlen(mat[i].title), " / %s", mat2[i].title); } - if (mat2 && (strcmp(mat[i].legend, mat2[i].legend) != 0)) + if (strcmp(mat[i].legend, mat2[i].legend) != 0) { sprintf(mat[i].legend+strlen(mat[i].legend), " / %s", mat2[i].legend); } diff --git a/src/gromacs/gmxana/levenmar.c b/src/gromacs/gmxana/levenmar.c index b1f6502770..9ec4716ad8 100644 --- a/src/gromacs/gmxana/levenmar.c +++ b/src/gromacs/gmxana/levenmar.c @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013, by the GROMACS development team, led by + * Copyright (c) 2013,2014, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -68,6 +68,8 @@ static real *rvector(int nl, int nh) { nrerror("allocation failure in rvector()", TRUE); } + /* cppcheck-suppress memleak + * free_vector does the same vector arithmetic */ return v-nl; } @@ -80,6 +82,8 @@ static int *ivector(int nl, int nh) { nrerror("allocation failure in ivector()", TRUE); } + /* cppcheck-suppress memleak + * free_vector does the same vector arithmetic */ return v-nl; } diff --git a/src/gromacs/gmxana/sfactor.c b/src/gromacs/gmxana/sfactor.c index 9bb0b9eaa6..4f99360496 100644 --- a/src/gromacs/gmxana/sfactor.c +++ b/src/gromacs/gmxana/sfactor.c @@ -350,8 +350,6 @@ extern void rearrange_atoms (reduced_atom_t * positions, t_trxframe *fr, atom_id { copy_rvec (fr->x[index[i]], pos[i].x); } - - positions = (reduced_atom_t *)pos; } diff --git a/src/gromacs/gmxlib/checkpoint.c b/src/gromacs/gmxlib/checkpoint.c index c718cb7151..609278b10b 100644 --- a/src/gromacs/gmxlib/checkpoint.c +++ b/src/gromacs/gmxlib/checkpoint.c @@ -465,6 +465,8 @@ static int do_cpte_reals_low(XDR *xd, int cptp, int ecpt, int sflags, { if (dtc == xdr_datatype_double) { + /* cppcheck-suppress invalidPointerCast + * Only executed if real is anyhow double */ vd = (double *)vp; } else @@ -716,7 +718,6 @@ static int do_cpte_nmatrix(XDR *xd, int cptp, int ecpt, int sflags, } for (i = 0; i < n; i++) { - reti = 0; vr = v[i]; reti = do_cpte_reals_low(xd, cptp, ecpt, sflags, n, NULL, &(v[i]), NULL, ecprREAL); if (list && reti == 0) @@ -1281,7 +1282,6 @@ static int do_cpt_enerhist(XDR *xd, gmx_bool bRead, { enerhist->ener_sum_sim[i] = enerhist->ener_sum[i]; } - fflags |= (1<nsteps = enerhist->nsum; - fflags |= (1<nsteps_sim = enerhist->nsum_sim; - fflags |= (1<nr; i++) { (void) pr_indent(fp, indent+INDENT); - (void) fprintf(fp, "%s->index[%d]=%u\n", + (void) fprintf(fp, "%s->index[%d]=%d\n", title, bShowNumbers ? i : -1, block->index[i]); } for (i = 0; i < block->nra; i++) { (void) pr_indent(fp, indent+INDENT); - (void) fprintf(fp, "%s->a[%d]=%u\n", + (void) fprintf(fp, "%s->a[%d]=%d\n", title, bShowNumbers ? i : -1, block->a[i]); } } @@ -1605,7 +1605,7 @@ void pr_blocka(FILE *fp, int indent, const char *title, t_blocka *block, gmx_boo (void) fprintf(fp, "\n"); size = pr_indent(fp, indent+INDENT); } - size += fprintf(fp, "%u", block->a[j]); + size += fprintf(fp, "%d", block->a[j]); } (void) fprintf(fp, "}\n"); start = end; diff --git a/src/gromacs/gmxpreprocess/calc_verletbuf.c b/src/gromacs/gmxpreprocess/calc_verletbuf.c index 7db60fae41..0dd3d502c7 100644 --- a/src/gromacs/gmxpreprocess/calc_verletbuf.c +++ b/src/gromacs/gmxpreprocess/calc_verletbuf.c @@ -414,6 +414,7 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t *mtop, add_at(&att, &natt, &prop[a], nmol); } + /* cppcheck-suppress uninitvar Fixed in cppcheck 1.65 */ sfree(vsite_m); sfree(prop); } diff --git a/src/gromacs/gmxpreprocess/gen_ad.c b/src/gromacs/gmxpreprocess/gen_ad.c index ba1e3d42dc..b0be7de0d2 100644 --- a/src/gromacs/gmxpreprocess/gen_ad.c +++ b/src/gromacs/gmxpreprocess/gen_ad.c @@ -210,7 +210,7 @@ static void rm2par(t_param p[], int *np, peq eq) { fprintf(debug, "Something VERY strange is going on in rm2par (gen_ad.c)\n" - "a[0] %u a[1] %u a[2] %u a[3] %u\n", + "a[0] %d a[1] %d a[2] %d a[3] %d\n", p[i].a[0], p[i].a[1], p[i].a[2], p[i].a[3]); } strcpy(p[i].s, ""); diff --git a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c index 7dc3f87a41..069402ca65 100644 --- a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c @@ -106,7 +106,7 @@ void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t *mtop, rvec v[]) if (seed == 0) { seed = gmx_rng_make_seed(); - fprintf(stderr, "Using random seed %d for generating velocities\n", seed); + fprintf(stderr, "Using random seed %u for generating velocities\n", seed); } rng = gmx_rng_init(seed); diff --git a/src/gromacs/gmxpreprocess/gen_vsite.c b/src/gromacs/gmxpreprocess/gen_vsite.c index a5f06b0c88..26704fa3d2 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.c +++ b/src/gromacs/gmxpreprocess/gen_vsite.c @@ -2155,7 +2155,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype, { if (debug) { - fprintf(debug, " [%u -> %u]", params->param[i].a[j], + fprintf(debug, " [%d -> %d]", params->param[i].a[j], params->param[i].a[j]-add_shift); } params->param[i].a[j] = params->param[i].a[j]-add_shift; @@ -2164,7 +2164,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype, { if (debug) { - fprintf(debug, " [%u -> %d]", params->param[i].a[j], + fprintf(debug, " [%d -> %d]", params->param[i].a[j], o2n[params->param[i].a[j]]); } params->param[i].a[j] = o2n[params->param[i].a[j]]; diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.c b/src/gromacs/gmxpreprocess/gpp_atomtype.c index ca66a1f85c..aa30dff10f 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.c +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.c @@ -370,7 +370,6 @@ void done_atomtype(gpp_atomtype_t ga) sfree(ga->atomnumber); ga->nr = 0; sfree(ga); - ga = NULL; } static int search_atomtypes(gpp_atomtype_t ga, int *n, int typelist[], diff --git a/src/gromacs/gmxpreprocess/readir.c b/src/gromacs/gmxpreprocess/readir.c index ac177033cb..8c3da5f6f0 100644 --- a/src/gromacs/gmxpreprocess/readir.c +++ b/src/gromacs/gmxpreprocess/readir.c @@ -3080,7 +3080,7 @@ static void make_swap_groups( void make_IMD_group(t_IMD *IMDgroup, char *IMDgname, t_blocka *grps, char **gnames) { - int ig = -1, i; + int ig, i; ig = search_string(IMDgname, grps->nr, gnames); diff --git a/src/gromacs/gmxpreprocess/solvate.cpp b/src/gromacs/gmxpreprocess/solvate.cpp index ae7ce1187a..5b5d336fc4 100644 --- a/src/gromacs/gmxpreprocess/solvate.cpp +++ b/src/gromacs/gmxpreprocess/solvate.cpp @@ -116,8 +116,10 @@ static void sort_molecule(t_atoms **atoms_solvt, rvec *x, rvec *v, real *r) moltp = NOTSET; for (j = 0; (j < nrmoltypes) && (moltp == NOTSET); j++) { - if (strcmp(*(atoms->resinfo[atoms->atom[i].resind].name), - moltypes[j].name) == 0) + /* cppcheck-suppress nullPointer + * moltypes is guaranteed to be allocated because otherwise + * nrmoltypes is 0. */ + if (strcmp(*(atoms->resinfo[atoms->atom[i].resind].name), moltypes[j].name) == 0) { moltp = j; } diff --git a/src/gromacs/gmxpreprocess/tomorse.c b/src/gromacs/gmxpreprocess/tomorse.c index abab6f87fe..8620bf62ab 100644 --- a/src/gromacs/gmxpreprocess/tomorse.c +++ b/src/gromacs/gmxpreprocess/tomorse.c @@ -282,6 +282,7 @@ void convert_harmonics(int nrmols, t_molinfo mols[], gpp_atomtype_t atype) last++; } } + /* cppcheck-suppress uninitvar Fixed in cppcheck 1.65 */ sfree(bRemoveHarm); fprintf(stderr, "Converted %d out of %d %s to morse bonds for mol %d\n", nrharm-last, nrharm, interaction_function[bb].name, i); diff --git a/src/gromacs/gmxpreprocess/topio.c b/src/gromacs/gmxpreprocess/topio.c index 87fd8a7a97..fd7d2e50e2 100644 --- a/src/gromacs/gmxpreprocess/topio.c +++ b/src/gromacs/gmxpreprocess/topio.c @@ -1360,7 +1360,6 @@ static void generate_qmexcl_moltype(gmx_moltype_t *molt, unsigned char *grpnr, j = 0; while (j < molt->ilist[i].nr) { - bexcl = FALSE; a1 = molt->ilist[i].iatoms[j+1]; a2 = molt->ilist[i].iatoms[j+2]; bexcl = ((bQMMM[a1] && bQMMM[a2]) || diff --git a/src/gromacs/imd/imdsocket.c b/src/gromacs/imd/imdsocket.c index 8c0719eab5..52f00de8d5 100644 --- a/src/gromacs/imd/imdsocket.c +++ b/src/gromacs/imd/imdsocket.c @@ -131,7 +131,7 @@ extern IMDSocket* imdsock_create() extern int imdsock_bind(IMDSocket *sock, int port) { - int ret = -1; + int ret; #ifdef GMX_IMD @@ -141,6 +141,8 @@ extern int imdsock_bind(IMDSocket *sock, int port) /* Try to bind to address and port ...*/ ret = bind(sock->sockfd, (struct sockaddr *) &sock->address, sizeof(sock->address)); +#else + ret = -1; #endif if (ret) @@ -154,12 +156,14 @@ extern int imdsock_bind(IMDSocket *sock, int port) extern int imd_sock_listen(IMDSocket *sock) { - int ret = -1; + int ret; #ifdef GMX_IMD /* Try to set to listening state */ ret = listen(sock->sockfd, MAXIMDCONNECTIONS); +#else + ret = -1; #endif if (ret) @@ -173,7 +177,7 @@ extern int imd_sock_listen(IMDSocket *sock) extern IMDSocket* imdsock_accept(IMDSocket *sock) { - int ret = -1; + int ret; #ifdef GMX_IMD socklen_t length; @@ -205,7 +209,7 @@ extern IMDSocket* imdsock_accept(IMDSocket *sock) extern int imdsock_getport(IMDSocket *sock, int *port) { - int ret = -1; + int ret; #ifdef GMX_IMD struct sockaddr_in sin; socklen_t len; diff --git a/src/gromacs/math/utilities.c b/src/gromacs/math/utilities.c index ec2b9d4e60..805e5bc998 100644 --- a/src/gromacs/math/utilities.c +++ b/src/gromacs/math/utilities.c @@ -739,7 +739,6 @@ gmx_bool gmx_isfinite(real gmx_unused x) gmx_bool gmx_isnan(real x) { - /* cppcheck-suppress duplicateExpression */ return x != x; } diff --git a/src/gromacs/mdlib/constr.c b/src/gromacs/mdlib/constr.c index bf6d117950..4cc9d4982b 100644 --- a/src/gromacs/mdlib/constr.c +++ b/src/gromacs/mdlib/constr.c @@ -792,7 +792,7 @@ static void make_shake_sblock_serial(struct gmx_constr *constr, j, constr->nblocks, ncons); for (i = 0; (i < ncons); i++) { - fprintf(stderr, "i: %5d sb[i].blocknr: %5u\n", i, sb[i].blocknr); + fprintf(stderr, "i: %5d sb[i].blocknr: %5d\n", i, sb[i].blocknr); } for (j = 0; (j <= constr->nblocks); j++) { diff --git a/src/gromacs/mdlib/domdec.c b/src/gromacs/mdlib/domdec.c index f262572838..e45c02926c 100644 --- a/src/gromacs/mdlib/domdec.c +++ b/src/gromacs/mdlib/domdec.c @@ -1934,7 +1934,7 @@ static void write_dd_grid_pdb(const char *fn, gmx_int64_t step, snew(grid_r, 2*dd->nnodes); } - dd_gather(dd, 2*sizeof(rvec), grid_s[0], DDMASTER(dd) ? grid_r[0] : NULL); + dd_gather(dd, 2*sizeof(rvec), grid_s, DDMASTER(dd) ? grid_r : NULL); if (DDMASTER(dd)) { diff --git a/src/gromacs/mdlib/mdebin.c b/src/gromacs/mdlib/mdebin.c index a8e4a0fb6c..f7cd4a3256 100644 --- a/src/gromacs/mdlib/mdebin.c +++ b/src/gromacs/mdlib/mdebin.c @@ -734,7 +734,7 @@ static void print_lambda_vector(t_lambda *fep, int i, if (Nsep > 1) { /* and add the closing parenthesis */ - str += sprintf(str, ")"); + sprintf(str, ")"); } } diff --git a/src/gromacs/mdlib/minimize.c b/src/gromacs/mdlib/minimize.c index 46b84172b2..af9116e52d 100644 --- a/src/gromacs/mdlib/minimize.c +++ b/src/gromacs/mdlib/minimize.c @@ -1787,7 +1787,6 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, } stepsize = 1.0/fnorm; - converged = FALSE; /* Start the loop over BFGS steps. * Each successful step is counted, and we continue until diff --git a/src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda.cu b/src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda.cu index b57ceea04d..fe19707ddd 100644 --- a/src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda.cu +++ b/src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda.cu @@ -716,18 +716,18 @@ void nbnxn_cuda_set_cacheconfig(cuda_dev_info_t *devinfo) if (devinfo->prop.major >= 3) { /* Default kernel on sm 3.x 48/16 kB Shared/L1 */ - stat = cudaFuncSetCacheConfig(nb_kfunc_ener_prune_ptr[i][j], cudaFuncCachePreferShared); - stat = cudaFuncSetCacheConfig(nb_kfunc_ener_noprune_ptr[i][j], cudaFuncCachePreferShared); - stat = cudaFuncSetCacheConfig(nb_kfunc_noener_prune_ptr[i][j], cudaFuncCachePreferShared); + cudaFuncSetCacheConfig(nb_kfunc_ener_prune_ptr[i][j], cudaFuncCachePreferShared); + cudaFuncSetCacheConfig(nb_kfunc_ener_noprune_ptr[i][j], cudaFuncCachePreferShared); + cudaFuncSetCacheConfig(nb_kfunc_noener_prune_ptr[i][j], cudaFuncCachePreferShared); stat = cudaFuncSetCacheConfig(nb_kfunc_noener_noprune_ptr[i][j], cudaFuncCachePreferShared); } else { /* On Fermi prefer L1 gives 2% higher performance */ /* Default kernel on sm_2.x 16/48 kB Shared/L1 */ - stat = cudaFuncSetCacheConfig(nb_kfunc_ener_prune_ptr[i][j], cudaFuncCachePreferL1); - stat = cudaFuncSetCacheConfig(nb_kfunc_ener_noprune_ptr[i][j], cudaFuncCachePreferL1); - stat = cudaFuncSetCacheConfig(nb_kfunc_noener_prune_ptr[i][j], cudaFuncCachePreferL1); + cudaFuncSetCacheConfig(nb_kfunc_ener_prune_ptr[i][j], cudaFuncCachePreferL1); + cudaFuncSetCacheConfig(nb_kfunc_ener_noprune_ptr[i][j], cudaFuncCachePreferL1); + cudaFuncSetCacheConfig(nb_kfunc_noener_prune_ptr[i][j], cudaFuncCachePreferL1); stat = cudaFuncSetCacheConfig(nb_kfunc_noener_noprune_ptr[i][j], cudaFuncCachePreferL1); } CU_RET_ERR(stat, "cudaFuncSetCacheConfig failed"); diff --git a/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_ref_outer.h b/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_ref_outer.h index 955e708fae..cc6fb229b9 100644 --- a/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_ref_outer.h +++ b/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_ref_outer.h @@ -336,7 +336,6 @@ NBK_FUNC_NAME(_VgrpF) #undef HALF_LJ #undef CALC_COULOMB } - /* cppcheck-suppress duplicateBranch */ else if (do_coul) { #define CALC_COULOMB @@ -361,7 +360,6 @@ NBK_FUNC_NAME(_VgrpF) #undef HALF_LJ #undef CALC_COULOMB } - /* cppcheck-suppress duplicateBranch */ else if (do_coul) { #define CALC_COULOMB diff --git a/src/gromacs/mdlib/nbnxn_search.c b/src/gromacs/mdlib/nbnxn_search.c index 31fc34bc5e..3570d120d4 100644 --- a/src/gromacs/mdlib/nbnxn_search.c +++ b/src/gromacs/mdlib/nbnxn_search.c @@ -1373,14 +1373,13 @@ static void sort_columns_supersub(const nbnxn_search_t nbs, int cxy_start, int cxy_end, int *sort_work) { - int cxy; - int cx, cy, cz = -1, c = -1, ncz; - int na, ash, na_c, ind, a; - int subdiv_z, sub_z, na_z, ash_z; - int subdiv_y, sub_y, na_y, ash_y; - int subdiv_x, sub_x, na_x, ash_x; + int cxy; + int cx, cy, cz = -1, c = -1, ncz; + int na, ash, na_c, ind, a; + int subdiv_z, sub_z, na_z, ash_z; + int subdiv_y, sub_y, na_y, ash_y; + int subdiv_x, sub_x, na_x, ash_x; - /* cppcheck-suppress unassignedVariable */ nbnxn_bb_t bb_work_array[2], *bb_work_aligned; bb_work_aligned = (nbnxn_bb_t *)(((size_t)(bb_work_array+1)) & (~((size_t)15))); diff --git a/src/gromacs/mdlib/ns.c b/src/gromacs/mdlib/ns.c index 9ed1d8db91..1a0a4c3ff7 100644 --- a/src/gromacs/mdlib/ns.c +++ b/src/gromacs/mdlib/ns.c @@ -2132,7 +2132,7 @@ static int nsgrid_core(t_commrec *cr, t_forcerec *fr, gmx_ns_t *ns; atom_id **nl_lr_ljc, **nl_lr_one, **nl_sr; int *nlr_ljc, *nlr_one, *nsr; - gmx_domdec_t *dd = NULL; + gmx_domdec_t *dd; t_block *cgs = &(top->cgs); int *cginfo = fr->cginfo; /* atom_id *i_atoms,*cgsindex=cgs->index; */ @@ -2160,10 +2160,7 @@ static int nsgrid_core(t_commrec *cr, t_forcerec *fr, ns = &fr->ns; bDomDec = DOMAINDECOMP(cr); - if (bDomDec) - { - dd = cr->dd; - } + dd = cr->dd; bTriclinicX = ((YY < grid->npbcdim && (!bDomDec || dd->nc[YY] == 1) && box[YY][XX] != 0) || diff --git a/src/gromacs/mdlib/nsgrid.c b/src/gromacs/mdlib/nsgrid.c index 366beca6f9..ba3af27787 100644 --- a/src/gromacs/mdlib/nsgrid.c +++ b/src/gromacs/mdlib/nsgrid.c @@ -290,7 +290,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis */ /* Determine the shift for the corners of the triclinic box */ add_tric = izones_size[j]*box[j][i]/box[j][j]; - if (dd && dd->ndim == 1 && j == ZZ) + if (dd->ndim == 1 && j == ZZ) { /* With 1D domain decomposition the cg's are not in * the triclinic box, but trilinic x-y and rectangular y-z. diff --git a/src/gromacs/selection/sm_distance.cpp b/src/gromacs/selection/sm_distance.cpp index cff41bd41e..ad994ada08 100644 --- a/src/gromacs/selection/sm_distance.cpp +++ b/src/gromacs/selection/sm_distance.cpp @@ -230,7 +230,7 @@ init_data_common(int /* npar */, gmx_ana_selparam_t *param) static void init_common(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data) { - t_methoddata_distance *d = (t_methoddata_distance *)data; + t_methoddata_distance *d = static_cast(data); if ((param[0].flags & SPAR_SET) && d->cutoff <= 0) { @@ -254,7 +254,7 @@ free_data_common(void *data) static void init_frame_common(t_topology * /* top */, t_trxframe * /* fr */, t_pbc *pbc, void *data) { - t_methoddata_distance *d = (t_methoddata_distance *)data; + t_methoddata_distance *d = static_cast(data); d->nbsearch.reset(); gmx::AnalysisNeighborhoodPositions pos(d->p.x, d->p.count()); @@ -272,7 +272,7 @@ static void evaluate_distance(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */, gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_distance *d = (t_methoddata_distance *)data; + t_methoddata_distance *d = static_cast(data); out->nr = pos->m.mapb.nra; for (int b = 0; b < pos->count(); ++b) @@ -296,7 +296,7 @@ static void evaluate_within(t_topology * /* top */, t_trxframe * /* fr */, t_pbc * /* pbc */, gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data) { - t_methoddata_distance *d = (t_methoddata_distance *)data; + t_methoddata_distance *d = static_cast(data); out->u.g->isize = 0; for (int b = 0; b < pos->count(); ++b) diff --git a/src/gromacs/simd/tests/base.h b/src/gromacs/simd/tests/base.h index 0f5c4dcca9..913b40352b 100644 --- a/src/gromacs/simd/tests/base.h +++ b/src/gromacs/simd/tests/base.h @@ -96,15 +96,14 @@ class SimdBaseTest : public ::testing::Test * conservative so it works with (inverse) square root, division, * exponentials, logarithms, and error functions. */ - SimdBaseTest() - { + SimdBaseTest() : #ifdef GMX_DOUBLE - ulpTol_ = 255LL; // Aim for roughly twice the precision we have in single. + ulpTol_(255LL), // Aim for roughly twice the precision we have in single. #else - ulpTol_ = 10LL; // Be a bit liberal so compiler optimization doesn't bite us. + ulpTol_(10LL), // Be a bit liberal so compiler optimization doesn't bite us. #endif - absTol_ = 0; - range_ = std::pair(1, 10); + absTol_(0), range_(std::pair(1, 10)) + { } /*! \brief Adjust ulp tolerance from the default 10 (float) or 255 (double). */ diff --git a/src/gromacs/utility/exceptions.cpp b/src/gromacs/utility/exceptions.cpp index 6dfc4330d8..bf0566d875 100644 --- a/src/gromacs/utility/exceptions.cpp +++ b/src/gromacs/utility/exceptions.cpp @@ -176,11 +176,15 @@ GromacsException::GromacsException(const ExceptionInitializer &details) const char *GromacsException::what() const throw() { const ErrorMessage *msg = boost::get_error_info(*this); - while (msg != NULL && msg->isContext()) + if (msg == NULL) + { + return "No reason provided"; + } + while (msg->isContext()) { msg = &msg->child(); } - return msg != NULL ? msg->text().c_str() : "No reason provided"; + return msg->text().c_str(); } void GromacsException::prependContext(const std::string &context) diff --git a/src/gromacs/utility/smalloc.c b/src/gromacs/utility/smalloc.c index 5414524689..8e08a34107 100644 --- a/src/gromacs/utility/smalloc.c +++ b/src/gromacs/utility/smalloc.c @@ -290,7 +290,6 @@ void *save_malloc_aligned(const char *name, const char *file, int line, } #endif - allocate_fail = FALSE; /* stop compiler warnings */ #ifdef HAVE_POSIX_MEMALIGN allocate_fail = (0 != posix_memalign(&malloced, alignment, nelem*elsize)); #elif defined HAVE_MEMALIGN diff --git a/tests/CppCheck.cmake b/tests/CppCheck.cmake index 2d6bda6895..cedcc1dfe6 100644 --- a/tests/CppCheck.cmake +++ b/tests/CppCheck.cmake @@ -57,6 +57,8 @@ if (CPPCHECK_EXECUTABLE AND UNIX) ${CMAKE_SOURCE_DIR}/src/external/*.c ${CMAKE_SOURCE_DIR}/src/external/*.cpp ${CMAKE_SOURCE_DIR}/src/external/*.cu + ${CMAKE_SOURCE_DIR}/src/gromacs/selection/scanner.cpp + ${CMAKE_SOURCE_DIR}/src/gromacs/selection/parser.cpp ) list(REMOVE_ITEM _inputfiles ${_files_to_ignore}) @@ -68,11 +70,12 @@ if (CPPCHECK_EXECUTABLE AND UNIX) set(_outputopt --xml) endif() set(_common_flags - --enable=style -DLINUX + --enable=style -DLINUX -DHAVE_UNISTD_H -I src/gromacs/legacyheaders -I src -I src/external/thread_mpi/include -I ${CMAKE_BINARY_DIR}/src -I ${CMAKE_BINARY_DIR}/src/gromacs/utility --quiet + --inline-suppr ${_outputopt}) set(_c_flags --suppress=variableScope @@ -84,15 +87,18 @@ if (CPPCHECK_EXECUTABLE AND UNIX) --suppress=sizeofCalculation --suppress=missingInclude:src/programs/mdrun/gmx_gpu_utils/gmx_gpu_utils.cu --suppress=*:src/external/Random123-1.08/include/Random123/features/compilerfeatures.h - --inline-suppr) + --suppress=assignIfError:src/gromacs/mdlib/nbnxn_atomdata.c #Ticket 5695 + --suppress=invalidPointerCast:src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda_kernel.cuh + --suppress=passedByValue:src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda_kernel.cuh + --suppress=passedByValue:src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda_kernel_utils.cuh + ) set(_cxx_flags -D__cplusplus --suppress=variableScope --suppress=unnecessaryForwardDeclaration --suppress=invalidscanf:src/gromacs/fileio/matio.cpp --suppress=invalidscanf:src/gromacs/fileio/xvgr.cpp - --suppress=invalidscanf:src/gromacs/gmxpreprocess/pdb2top.cpp - --suppress=*:src/gromacs/selection/scanner.cpp) + --suppress=invalidscanf:src/gromacs/gmxpreprocess/pdb2top.cpp) # This list will hold the list of all files with cppcheck errors # (one per input file)