Fix cppcheck 1.64 warnings
authorRoland Schulz <roland@utk.edu>
Sat, 19 Apr 2014 08:51:39 +0000 (04:51 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 27 Apr 2014 11:18:13 +0000 (13:18 +0200)
Related to #1487

Change-Id: I223289d71e0dfc426f382d1bcb53b3509202779f

50 files changed:
src/external/tng_io/src/lib/md5.c
src/gromacs/essentialdynamics/edsam.c
src/gromacs/fileio/gmxfio_asc.c
src/gromacs/fileio/md5.c
src/gromacs/fileio/trajectory_writing.c
src/gromacs/fileio/xdrd.c
src/gromacs/gmxana/edittop.c
src/gromacs/gmxana/gmx_bar.c
src/gromacs/gmxana/gmx_confrms.c
src/gromacs/gmxana/gmx_current.c
src/gromacs/gmxana/gmx_do_dssp.c
src/gromacs/gmxana/gmx_eneconv.c
src/gromacs/gmxana/gmx_hbond.c
src/gromacs/gmxana/gmx_hydorder.c
src/gromacs/gmxana/gmx_make_edi.c
src/gromacs/gmxana/gmx_mdmat.c
src/gromacs/gmxana/gmx_order.c
src/gromacs/gmxana/gmx_rms.c
src/gromacs/gmxana/gmx_tune_pme.c
src/gromacs/gmxana/gmx_vanhove.c
src/gromacs/gmxana/gmx_xpm2ps.c
src/gromacs/gmxana/levenmar.c
src/gromacs/gmxana/sfactor.c
src/gromacs/gmxlib/checkpoint.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxpreprocess/calc_verletbuf.c
src/gromacs/gmxpreprocess/gen_ad.c
src/gromacs/gmxpreprocess/gen_maxwell_velocities.c
src/gromacs/gmxpreprocess/gen_vsite.c
src/gromacs/gmxpreprocess/gpp_atomtype.c
src/gromacs/gmxpreprocess/readir.c
src/gromacs/gmxpreprocess/solvate.cpp
src/gromacs/gmxpreprocess/tomorse.c
src/gromacs/gmxpreprocess/topio.c
src/gromacs/imd/imdsocket.c
src/gromacs/math/utilities.c
src/gromacs/mdlib/constr.c
src/gromacs/mdlib/domdec.c
src/gromacs/mdlib/mdebin.c
src/gromacs/mdlib/minimize.c
src/gromacs/mdlib/nbnxn_cuda/nbnxn_cuda.cu
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_ref_outer.h
src/gromacs/mdlib/nbnxn_search.c
src/gromacs/mdlib/ns.c
src/gromacs/mdlib/nsgrid.c
src/gromacs/selection/sm_distance.cpp
src/gromacs/simd/tests/base.h
src/gromacs/utility/exceptions.cpp
src/gromacs/utility/smalloc.c
tests/CppCheck.cmake

index ea8bb37b5e0ed7d2c8f15e7c6bdab910eeb455de..0ab0367e78d078ede8530b78724103f838f5fec5 100644 (file)
@@ -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
 
index d2885ea278cdf24d5995e28334d6e816791273ee..1498500cceb125555c57fa5dda6445e41787d600 100644 (file)
@@ -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)
index e44dffed2cad170d4f3bbe922aba9caf25920ee7..50756f6c7c8bb9db2b55b5db697c19708437d964 100644 (file)
@@ -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] == '_')
         {
index ca27dbb75ae43d3f85bdfcadd5b77bb58af20300..e6a608ebf3ec6974d3690577166670f3b27d1a7f 100644 (file)
@@ -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
 
index f19020867d31b904a414ac45f0df01e401c0a933..5a55f8833170988bb59cbbfb6f86af4c35916876 100644 (file)
@@ -147,7 +147,6 @@ do_md_trajectory_writing(FILE           *fplog,
         if (bCPT)
         {
             (*nchkpt)++;
-            bCPT = FALSE;
         }
         debug_gmx();
         if (bLastStep && step_rel == ir->nsteps &&
index e05cbdd4fd84a16ed4cd9c7b28b240163074eca5..682e68cdd8e492a80e2019b3de24234b236b17a5 100644 (file)
@@ -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));
 
index 50dd7731c7308d9f2eb2c4395dbdab8212479811..9295f8c70ea4065e56b9327bc44ce79c5b0de262 100644 (file)
@@ -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);
     }
 }
index 18881595743e8a461cd6277b9e5836d42a80eb91..e71ec7e35ea5f82bd29045218b386bb71e35b2ba 100644 (file)
@@ -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]);
         }
     }
 }
index 37f90b9d08ab54fb5151dff90763bb23c0e25825..82bc68263bacef23695b0d96df1683ff6c1c1a61 100644 (file)
@@ -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)
         {
index 19bd0a0beac693dd1fe3a5b951e67b1e010e4dfc..171a7a91c24a01075cead154acbab4a26a0306b1 100644 (file)
@@ -36,6 +36,7 @@
 #include <config.h>
 #endif
 
+#include <assert.h>
 #include <stdlib.h>
 
 #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)
index d3fdbb995224fddf4b88ea273c0248b2734b3c18..f90e2f0bf5b456d84e51d53f9e1a9092fba89d88 100644 (file)
@@ -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;
index ef58eca11415a7d66f0a7a5815da08455f0fd21c..3e87f0dbd4ad54e1de85339fdee034dba69e2fcb 100644 (file)
@@ -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;
 
index 3a86c9780edcc33bfcc6ae944e63aa3b73d1e95d..0a0b6d88e319a09d71873b067762eb38ad5d0c95 100644 (file)
@@ -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))
             {
index c6fb42a8ba1914421ce56ae8bf1ff2343dd3d7b9..a86c35327e3325079121d1c97b160d399cef50ca 100644 (file)
@@ -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");
index c2b85efcef447f43703117d018660e2ed71833d5..bc869d2657a59bd7b20d69c04ac14a23d3bd9985 100644 (file)
@@ -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*/
index d11ca0d2f4dc2119f36f55aafce1fd64b5f07004..c3e046ab9c64213ac858ef6b3cbbaa8d5e304a0f 100644 (file)
@@ -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;
 
index 409918c90d5e152f34a905ea399f82038c978c52..12902c9167f2af17f52d533aa91f83f5489a3aa6 100644 (file)
@@ -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");
index a059824da86ff184abd3cf36428c8929542ab8c7..28cd76faf3ae735397435e26cf1f19d5087ba850 100644 (file)
@@ -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;
index 2e0aeb11a4f1852d0b1bd722ea208c1c352932be..dcd777874040b174c91ab7e746acb2597aa83fc0 100644 (file)
@@ -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] &&
index 934099757d8900e7fc525a40828ec284e77db8eb..640d786db9000a5dbbf731f11a837e29bf90b4de 100644 (file)
@@ -38,6 +38,7 @@
 #include <config.h>
 #endif
 
+#include <assert.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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]);
index 9c3ae9b00df399c482d811c83792c382161f0d1d..d230bca60f6bcb8c349ef60d0246c9f6c282d5e3 100644 (file)
@@ -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);
             }
index b1f6502770f0b9b04866c370d23bc1184d0e257e..9ec4716ad80045eade179e2e9eee90e8f7be373e 100644 (file)
@@ -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;
 }
 
index 9bb0b9eaa6de08075de0a8cb302785237f81efa8..4f99360496bbd2c4f0b8957d8975f44883697a2a 100644 (file)
@@ -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;
 }
 
 
index c718cb715197ef4ad3b4365694de0cd9f69701ab..609278b10b9f4311bcff0ac65c21ebadf5263c78 100644 (file)
@@ -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<<eenhENERGY_SUM_SIM);
     }
 
     if ( (fflags & (1<<eenhENERGY_NSUM)) &&
@@ -1289,14 +1289,12 @@ static int do_cpt_enerhist(XDR *xd, gmx_bool bRead,
     {
         /* Assume we have an old file format and copy nsum to nsteps */
         enerhist->nsteps = enerhist->nsum;
-        fflags          |= (1<<eenhENERGY_NSTEPS);
     }
     if ( (fflags & (1<<eenhENERGY_NSUM_SIM)) &&
          !(fflags & (1<<eenhENERGY_NSTEPS_SIM)))
     {
         /* Assume we have an old file format and copy nsum to nsteps */
         enerhist->nsteps_sim = enerhist->nsum_sim;
-        fflags              |= (1<<eenhENERGY_NSTEPS_SIM);
     }
 
     return ret;
index 96dde56e6eda763dd0e46aec64aa522fe43791ee..eceff44a2f9e730ffc14ad85c8e83f450d295f30 100644 (file)
@@ -1518,13 +1518,13 @@ static void low_pr_blocka(FILE *fp, int indent, const char *title, t_blocka *blo
         for (i = 0; i <= block->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;
index 7db60fae413ccd19d5861d30bf47e2f410962775..0dd3d502c7d06ab88c3da2acb9906ed161cdccd1 100644 (file)
@@ -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);
     }
index ba1e3d42dc3db79ca60441fbbc19c598b54ad72f..b0be7de0d2fe652bd0c12f98fd17a6a1d1d12e22 100644 (file)
@@ -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, "");
index 7dc3f87a414bfbc9c55d093591c3407c069d9978..069402ca657c51534f38bcba9e6f4b075ca229ea 100644 (file)
@@ -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);
index a5f06b0c881e0f4d89d194547afa5a5371b437c3..26704fa3d285b8ae250a751fd842b9a2eee9fe77 100644 (file)
@@ -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]];
index ca66a1f85c4d6670fb1575de9d5e50d331cbf152..aa30dff10f54c0da16b26f5c247452cdea1bbb26 100644 (file)
@@ -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[],
index ac177033cbfee295cc8813d5491d2d926896133f..8c3da5f6f07a3ffd7a8029c2dff0ad4891b361b6 100644 (file)
@@ -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);
index ae7ce1187a6735862ac4200e56bec8263757cb9a..5b5d336fc4d9449f24bdff2ae65d3aac2d02d9d2 100644 (file)
@@ -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;
                 }
index abab6f87fe1d290ce3092308ca5ed4247292e458..8620bf62ab129d4e00225f2ed58f09b1cd17f9f0 100644 (file)
@@ -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);
index 87fd8a7a978a60c684b1f04d34b6e14a82744547..fd7d2e50e2e1a2c9b63c414961f4e5ac99ac238d 100644 (file)
@@ -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]) ||
index 8c0719eab5efc0c077d90bdc6c419aca8f5b9817..52f00de8d56a1acb206145d6ca5f39040bab362a 100644 (file)
@@ -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;
index ec2b9d4e60a09cb1ab0b5056a2dcfcd7681510ad..805e5bc998672ac2430239e68d0ca34b17db494d 100644 (file)
@@ -739,7 +739,6 @@ gmx_bool gmx_isfinite(real gmx_unused x)
 
 gmx_bool gmx_isnan(real x)
 {
-    /* cppcheck-suppress duplicateExpression */
     return x != x;
 }
 
index bf6d117950b5d9a90abedbf9762dc6151323b0b3..4cc9d4982bf4e2ee39f1552ebb2fb2a9b4d298d4 100644 (file)
@@ -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++)
         {
index f262572838ca1bf718925d8c8cd972ba886530dd..e45c02926ca42ddbbd968e2814b4b5f482ae50c3 100644 (file)
@@ -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))
     {
index a8e4a0fb6cabfc27cc915856f5a40a6e48bf2036..f7cd4a32569480ba437d50192932c365ff6ebb57 100644 (file)
@@ -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, ")");
     }
 }
 
index 46b84172b202e39a85d2d414ce0c0282f9ffa037..af9116e52dbfa8abe896fad6bec539f5b9fd0750 100644 (file)
@@ -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
index b57ceea04d42ae0b2590acb9c87f4697f161a93d..fe19707ddd80376d3ad14521eff25d2bd194894d 100644 (file)
@@ -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");
index 955e708fae8994866423b554059a97d028f615d9..cc6fb229b9911b41cd996f0e15ee0103ff9a4445 100644 (file)
@@ -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
index 31fc34bc5ea6abb7c33f10e1eea1e3c766e22c6b..3570d120d4f7c60929baaf2eb1aa094b9a0b7235 100644 (file)
@@ -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)));
index 9ed1d8db91901228e1a9e91db1da4903fa03b97b..1a0a4c3ff7cae1d3373e3aa3853bb94d48100f4e 100644 (file)
@@ -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) ||
index 366beca6f992b48d52bd3e8dd5a59d2a93b28dfb..ba3af277874f1744ddf2fa2a0ed70c4791d6e802 100644 (file)
@@ -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.
index cff41bd41e8ddba5106b671a2c5fb4f70a71b020..ad994ada0825c1db0ebb83bc98759be7e01c7e6f 100644 (file)
@@ -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<t_methoddata_distance *>(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<t_methoddata_distance *>(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<t_methoddata_distance *>(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<t_methoddata_distance *>(data);
 
     out->u.g->isize = 0;
     for (int b = 0; b < pos->count(); ++b)
index 0f5c4dcca980276bcbbc0a12acdbbc192fb34ee9..913b40352b100a1b34758e4648cb83a9c24a8890 100644 (file)
@@ -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<real, real>(1, 10);
+            absTol_(0), range_(std::pair<real, real>(1, 10))
+        {
         }
 
         /*! \brief Adjust ulp tolerance from the default 10 (float) or 255 (double). */
index 6dfc4330d83324b7c35ffc3d8d32beadb9d98f71..bf0566d875c73f3dd89740c224f970b746b53e36 100644 (file)
@@ -176,11 +176,15 @@ GromacsException::GromacsException(const ExceptionInitializer &details)
 const char *GromacsException::what() const throw()
 {
     const ErrorMessage *msg = boost::get_error_info<errinfo_message>(*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)
index 54145246890fe1092ddc90470bf543796cdb54e5..8e08a341072d9d848d2d44848eca7eed504f616e 100644 (file)
@@ -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
index 2d6bda6895030bd3c163deefa3a8395e5cedab3d..cedcc1dfe6c7b650ef89e1f0b2260767409ed224 100644 (file)
@@ -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)