Fix cppcheck-1.67 warnings
authorRoland Schulz <roland@utk.edu>
Sun, 14 Dec 2014 20:25:53 +0000 (15:25 -0500)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 17 Dec 2014 09:05:53 +0000 (10:05 +0100)
Remove suppressions for previous cppcheck versions

Change-Id: Ifb03e7b2300b65ca8adb8e22b71da25ea472be52

20 files changed:
src/gromacs/correlationfunctions/expfit.c
src/gromacs/correlationfunctions/tests/expfit.cpp
src/gromacs/essentialdynamics/edsam.c
src/gromacs/fileio/gmxfio_asc.c
src/gromacs/gmxana/edittop.c
src/gromacs/gmxana/geminate.c
src/gromacs/gmxana/gmx_anaeig.c
src/gromacs/gmxana/gmx_analyze.c
src/gromacs/gmxana/gmx_densmap.c
src/gromacs/gmxana/gmx_dos.c
src/gromacs/gmxana/gmx_dyndom.c
src/gromacs/gmxpreprocess/calc_verletbuf.c
src/gromacs/gmxpreprocess/readir.c
src/gromacs/gmxpreprocess/tomorse.c
src/gromacs/gmxpreprocess/toppush.c
src/gromacs/math/utilities.h
src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_simd_utils_x86_256s.h
src/gromacs/topology/mtop_util.c
src/programs/view/xdlg.cpp
tests/CppCheck.cmake

index 704943c3279fa52f895754baaad13d1ba58fa101..490e0be4f83cbeb64aadb4fe524b27d17be8e630 100644 (file)
@@ -285,7 +285,7 @@ static double lmc_errest_3_parm(double x, const double *a)
 
     if (a[0] != 0)
     {
-        e1 = exp(-x/a[0]) - 1;
+        e1 = gmx_expm1(-x/a[0]);
     }
     else
     {
@@ -293,7 +293,7 @@ static double lmc_errest_3_parm(double x, const double *a)
     }
     if (a[2] != 0)
     {
-        e2 = exp(-x/a[2]) - 1;
+        e2 = gmx_expm1(-x/a[2]);
     }
     else
     {
index 4da434691d742c07ec1c3189ec1aaf6ea7198f0e..356919269726a6f5ac3de9f77001e2878fa68e3c 100755 (executable)
@@ -144,6 +144,7 @@ class ExpfitTest : public ::testing::Test
 
 //static var
 int               ExpfitTest::nrLines_;
+//cppcheck-suppress arrayIndexOutOfBounds fixed in 1.68-dev
 std::vector<real> ExpfitTest::values_[expTestNrTypes];
 int               ExpfitTest::nrColumns_;
 std::vector<real> ExpfitTest::standardDev_;
index 299842d375fa77cef168fe00f15d24cc061120c4..5514403870b5a8fb29647276dbe46254230c55e2 100644 (file)
@@ -1793,7 +1793,6 @@ 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 f819a8d7a0a25c2a6199ce73f4cffe80e0799680..a451b0c072b644d237b1284c8369de90c019505c 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #include <stdio.h>
@@ -361,6 +362,7 @@ static gmx_bool do_ascread(t_fileio *fio, void *item, int nitem, int eio,
             }
             break;
         case eioNRVEC:
+            assert(item);
             for (i = 0; (i < nitem); i++)
             {
                 ptr = ((rvec *) item)[i];
@@ -368,10 +370,7 @@ static gmx_bool do_ascread(t_fileio *fio, void *item, int nitem, int eio,
                 {
                     res = sscanf(next_item(fp, ni_buf, NEXT_ITEM_BUF_LEN), "%lf\n",
                                  &x);
-                    if (item)
-                    {
-                        ptr[m] = x;
-                    }
+                    ptr[m] = x;
                 }
             }
             break;
index 3a5357c731391c6711b76f87aeb7a406f4a88088..0338366db0c28712d22cfa6e082b7ab043812287 100644 (file)
@@ -110,7 +110,6 @@ 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 2b8603dfe68e59f02168eec0086eaf6f975c277e..d06a4b41d8e91e8ffde3df410454fe98a4181083 100644 (file)
@@ -515,7 +515,7 @@ static double eq10v2(double theoryCt[], double time[], int manytimes,
 /* This returns the real-valued index(!) to an ACF, equidistant on a log scale. */
 static double getLogIndex(const int i, const t_gemParams *params)
 {
-    return (exp(((double)(i)) * params->logQuota) -1);
+    return gmx_expm1(((double)(i)) * params->logQuota);
 }
 
 extern t_gemParams *init_gemParams(const double sigma, const double D,
index 4a219adf2cc4247d90b625639a963f60656a30a9..d9ea3facf922cdeae384fefee38d1df19f4c348b 100644 (file)
@@ -76,7 +76,7 @@ static void calc_entropy_qh(FILE *fp, int n, real eigval[], real temp, int nskip
             lambda = eigval[i]*AMU;
             w      = sqrt(BOLTZMANN*temp/lambda)/NANO;
             hwkT   = (hbar*w)/(BOLTZMANN*temp);
-            dS     = (hwkT/(exp(hwkT) - 1) - log(1-exp(-hwkT)));
+            dS     = (hwkT/gmx_expm1(hwkT) - gmx_log1p(-exp(-hwkT)));
             S     += dS;
             if (debug)
             {
index 8d1eab6bee08e2ce8bb27576d8717a506d94a437..1c323e14b23d6bdc14879c6e80ad3ba907d8d05a 100644 (file)
@@ -89,7 +89,7 @@ static void power_fit(int n, int nset, real **val, real *t)
         fprintf(stdout, "First time is not larger than 0, using index number as time for power fit\n");
         for (i = 0; i < n; i++)
         {
-            x[i] = log(i+1);
+            x[i] = gmx_log1p(i);
         }
     }
 
index 03bc88dd11495173ec16d5a96cd86ae0aafab9bf..bf263eae7fa06d80a51309b9e342a59a985cef57 100644 (file)
@@ -246,7 +246,9 @@ int gmx_densmap(int argc, char *argv[])
     {
         n1      = (int)(2*amax/bin + 0.5);
         nradial = (int)(rmax/bin + 0.5);
+        /* cppcheck-suppress zerodiv fixed in 1.68-dev */
         invspa  = n1/(2*amax);
+        /* cppcheck-suppress zerodiv fixed in 1.68-dev */
         invspz  = nradial/rmax;
         if (bMirror)
         {
index 560ab280f550d58b14275e0c2a87c726f7b7fe2e..52a7d9d61ef50703e1d77167b23039cee49b8b36 100644 (file)
@@ -181,7 +181,7 @@ static real wSsolid(real nu, real beta)
     }
     else
     {
-        return bhn/(exp(bhn)-1) - log(1-exp(-bhn));
+        return bhn/gmx_expm1(bhn) - gmx_log1p(-exp(-bhn));
     }
 }
 
@@ -209,7 +209,7 @@ static real wEsolid(real nu, real beta)
     }
     else
     {
-        return bhn/2 + bhn/(exp(bhn)-1)-1;
+        return bhn/2 + bhn/gmx_expm1(bhn)-1;
     }
 }
 
index 5a727cb1c2317a7e5391eabde550148b8bd02964..63fb697756d84766509652fadefec326d89c0a35 100644 (file)
@@ -208,6 +208,11 @@ int gmx_dyndom(int argc, char *argv[])
         return 0;
     }
 
+    if (maxangle == 0)
+    {
+        gmx_fatal(FARGS, "maxangle not given");
+    }
+
     get_stx_coordnum (opt2fn("-f", NFILE, fnm), &natoms);
     init_t_atoms(&atoms, natoms, TRUE);
     snew(x, natoms);
index 3ace4d48ab811bd135e36f95fc3ee50c2adb57c6..0116bfeb04215bd6b68169a60994786ce04059d3 100644 (file)
@@ -414,7 +414,6 @@ 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 2510750b83eb6efd7a520c46ff033a495eba12c4..1b76bae97c168709dc35dc3fb22f9d139ad0c62a 100644 (file)
@@ -159,7 +159,7 @@ static void GetSimTemps(int ntemps, t_simtemp *simtemp, double *temperature_lamb
         }
         else if (simtemp->eSimTempScale == esimtempEXPONENTIAL)
         {
-            simtemp->temperatures[i] = simtemp->simtemp_low + (simtemp->simtemp_high-simtemp->simtemp_low)*((exp(temperature_lambdas[i])-1)/(exp(1.0)-1));
+            simtemp->temperatures[i] = simtemp->simtemp_low + (simtemp->simtemp_high-simtemp->simtemp_low)*(gmx_expm1(temperature_lambdas[i])/gmx_expm1(1.0));
         }
         else
         {
index f1781e90432994261ac8dde60a65d6f2711efe93..cd9b793b5fb3b2bc75cd9c8b049cc73668da52cd 100644 (file)
@@ -280,7 +280,6 @@ 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 8272b7787ecf3f2dad111040e9d2ca76dca6b884..832a2a12037fdd70864944b4f56605199393e290 100644 (file)
@@ -485,6 +485,7 @@ void push_at (t_symtab *symtab, gpp_atomtype_t at, t_bond_atomtype bat,
         gmx_fatal(FARGS, "Invalid particle type %s on line %s",
                   ptype, line);
     }
+    /* cppcheck-suppress arrayIndexOutOfBounds #6329 */
     pt = xl[j].ptype;
     if (debug)
     {
index 2932220068bf53b5d43731c35882630a0f84d4ae..8647c00f80e33870fc4e302600b9b701436a4d7a 100644 (file)
@@ -98,6 +98,14 @@ float   gmx_erfcf(float x);
 #define gmx_erfc(x)  gmx_erfcf(x)
 #endif
 
+#if defined(_MSC_VER) && _MSC_VER < 1800
+#define gmx_expm1(x) (exp(x)-1)
+#define gmx_log1p(x) log(1+x)
+#else
+#define gmx_expm1 expm1
+#define gmx_log1p log1p
+#endif
+
 gmx_bool gmx_isfinite(real x);
 gmx_bool gmx_isnan(real x);
 
index 5caee76a48dfb1acbb151edbbb66ea58fd0471ee..52a081ae9bae6bb1199ba4246f9d36a08bdd8997 100644 (file)
@@ -312,6 +312,7 @@ gmx_load1_exclfilter(int e)
 static gmx_inline gmx_exclfilter gmx_simdcall
 gmx_load_exclusion_filter(const unsigned *i)
 {
+    /* cppcheck-suppress invalidPointerCast */
     return gmx_simd_load_r((real *) (i));
 }
 
index 19fd0927dcb472479cad967a581139c2ada0ad9d..24eb127af26c37942623e8894c977b917d2c1f5a 100644 (file)
@@ -411,9 +411,11 @@ void gmx_mtop_atominfo_global(const gmx_mtop_t *mtop, int atnr_global,
     {
         if (mb >= 0)
         {
+            /* cppcheck-suppress nullPointer #6330*/
             if (atoms->nres <= mtop->maxres_renum)
             {
                 /* Single residue molecule, keep counting */
+                /* cppcheck-suppress nullPointer #6330*/
                 maxresnr += mtop->molblock[mb].nmol*atoms->nres;
             }
         }
index 4c3d4375ac2cfa1a33d05f8bc9e5013f1815e65b..2719c42b80a95fef1b21a0f76e638639ca677f4a 100644 (file)
@@ -408,11 +408,14 @@ void HelpNow(t_dlg *dlg, t_dlgitem *dlgitem)
         if (gmx_strcasecmp(buf, "nok") == 0)
         {
             /* An error occurred */
-            for (i = 0; (i < nlines); i++)
+            if (lines)
             {
-                sfree(lines[i]);
+                for (i = 0; (i < nlines); i++)
+                {
+                    sfree(lines[i]);
+                }
+                sfree(lines);
             }
-            sfree(lines);
             NoHelp(dlg);
             return;
         }
index 0f7917271f307c9a936f1804ca503c7a4f5c0a55..767631b715c3e360b91918ef250fdc461eb3240f 100644 (file)
@@ -86,9 +86,9 @@ if (CPPCHECK_EXECUTABLE AND UNIX)
         --suppress=unusedStructMember
         --suppress=invalidscanf
         --suppress=sizeofCalculation
+        --suppress=invalidscanf_libc
         --suppress=missingInclude:src/programs/mdrun/gmx_gpu_utils/gmx_gpu_utils.cu
         --suppress=*:src/external/Random123-1.08/include/Random123/features/compilerfeatures.h
-        --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
@@ -97,10 +97,9 @@ if (CPPCHECK_EXECUTABLE AND UNIX)
         -D__cplusplus
         --suppress=variableScope
         --suppress=unnecessaryForwardDeclaration
-        --suppress=invalidscanf:src/gromacs/fileio/matio.cpp
-        --suppress=invalidscanf:src/gromacs/fileio/xvgr.cpp
-        --suppress=invalidscanf:src/gromacs/topology/index.cpp
-        --suppress=invalidscanf:src/gromacs/gmxpreprocess/pdb2top.cpp
+        --suppress=memsetClassFloat  #we assume IEEE754
+        --suppress=invalidscanf_libc #seems only important for security on non-std libc
+        --suppress=invalidscanf      #same as last (style and portability checker have the same warning)
         --suppress=passedByValue:src/gromacs/simd/tests/*
         )