From: Roland Schulz Date: Sun, 14 Dec 2014 20:25:53 +0000 (-0500) Subject: Fix cppcheck-1.67 warnings X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=0133d36469f897b16f36a2591a389110d66aac0c;p=alexxy%2Fgromacs.git Fix cppcheck-1.67 warnings Remove suppressions for previous cppcheck versions Change-Id: Ifb03e7b2300b65ca8adb8e22b71da25ea472be52 --- diff --git a/src/gromacs/correlationfunctions/expfit.c b/src/gromacs/correlationfunctions/expfit.c index 704943c327..490e0be4f8 100644 --- a/src/gromacs/correlationfunctions/expfit.c +++ b/src/gromacs/correlationfunctions/expfit.c @@ -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 { diff --git a/src/gromacs/correlationfunctions/tests/expfit.cpp b/src/gromacs/correlationfunctions/tests/expfit.cpp index 4da434691d..3569192697 100755 --- a/src/gromacs/correlationfunctions/tests/expfit.cpp +++ b/src/gromacs/correlationfunctions/tests/expfit.cpp @@ -144,6 +144,7 @@ class ExpfitTest : public ::testing::Test //static var int ExpfitTest::nrLines_; +//cppcheck-suppress arrayIndexOutOfBounds fixed in 1.68-dev std::vector ExpfitTest::values_[expTestNrTypes]; int ExpfitTest::nrColumns_; std::vector ExpfitTest::standardDev_; diff --git a/src/gromacs/essentialdynamics/edsam.c b/src/gromacs/essentialdynamics/edsam.c index 299842d375..5514403870 100644 --- a/src/gromacs/essentialdynamics/edsam.c +++ b/src/gromacs/essentialdynamics/edsam.c @@ -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) diff --git a/src/gromacs/fileio/gmxfio_asc.c b/src/gromacs/fileio/gmxfio_asc.c index f819a8d7a0..a451b0c072 100644 --- a/src/gromacs/fileio/gmxfio_asc.c +++ b/src/gromacs/fileio/gmxfio_asc.c @@ -38,6 +38,7 @@ #include "config.h" +#include #include #include #include @@ -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; diff --git a/src/gromacs/gmxana/edittop.c b/src/gromacs/gmxana/edittop.c index 3a5357c731..0338366db0 100644 --- a/src/gromacs/gmxana/edittop.c +++ b/src/gromacs/gmxana/edittop.c @@ -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); } } diff --git a/src/gromacs/gmxana/geminate.c b/src/gromacs/gmxana/geminate.c index 2b8603dfe6..d06a4b41d8 100644 --- a/src/gromacs/gmxana/geminate.c +++ b/src/gromacs/gmxana/geminate.c @@ -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, diff --git a/src/gromacs/gmxana/gmx_anaeig.c b/src/gromacs/gmxana/gmx_anaeig.c index 4a219adf2c..d9ea3facf9 100644 --- a/src/gromacs/gmxana/gmx_anaeig.c +++ b/src/gromacs/gmxana/gmx_anaeig.c @@ -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) { diff --git a/src/gromacs/gmxana/gmx_analyze.c b/src/gromacs/gmxana/gmx_analyze.c index 8d1eab6bee..1c323e14b2 100644 --- a/src/gromacs/gmxana/gmx_analyze.c +++ b/src/gromacs/gmxana/gmx_analyze.c @@ -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); } } diff --git a/src/gromacs/gmxana/gmx_densmap.c b/src/gromacs/gmxana/gmx_densmap.c index 03bc88dd11..bf263eae7f 100644 --- a/src/gromacs/gmxana/gmx_densmap.c +++ b/src/gromacs/gmxana/gmx_densmap.c @@ -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) { diff --git a/src/gromacs/gmxana/gmx_dos.c b/src/gromacs/gmxana/gmx_dos.c index 560ab280f5..52a7d9d61e 100644 --- a/src/gromacs/gmxana/gmx_dos.c +++ b/src/gromacs/gmxana/gmx_dos.c @@ -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; } } diff --git a/src/gromacs/gmxana/gmx_dyndom.c b/src/gromacs/gmxana/gmx_dyndom.c index 5a727cb1c2..63fb697756 100644 --- a/src/gromacs/gmxana/gmx_dyndom.c +++ b/src/gromacs/gmxana/gmx_dyndom.c @@ -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); diff --git a/src/gromacs/gmxpreprocess/calc_verletbuf.c b/src/gromacs/gmxpreprocess/calc_verletbuf.c index 3ace4d48ab..0116bfeb04 100644 --- a/src/gromacs/gmxpreprocess/calc_verletbuf.c +++ b/src/gromacs/gmxpreprocess/calc_verletbuf.c @@ -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); } diff --git a/src/gromacs/gmxpreprocess/readir.c b/src/gromacs/gmxpreprocess/readir.c index 2510750b83..1b76bae97c 100644 --- a/src/gromacs/gmxpreprocess/readir.c +++ b/src/gromacs/gmxpreprocess/readir.c @@ -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 { diff --git a/src/gromacs/gmxpreprocess/tomorse.c b/src/gromacs/gmxpreprocess/tomorse.c index f1781e9043..cd9b793b5f 100644 --- a/src/gromacs/gmxpreprocess/tomorse.c +++ b/src/gromacs/gmxpreprocess/tomorse.c @@ -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); diff --git a/src/gromacs/gmxpreprocess/toppush.c b/src/gromacs/gmxpreprocess/toppush.c index 8272b7787e..832a2a1203 100644 --- a/src/gromacs/gmxpreprocess/toppush.c +++ b/src/gromacs/gmxpreprocess/toppush.c @@ -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) { diff --git a/src/gromacs/math/utilities.h b/src/gromacs/math/utilities.h index 2932220068..8647c00f80 100644 --- a/src/gromacs/math/utilities.h +++ b/src/gromacs/math/utilities.h @@ -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); diff --git a/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_simd_utils_x86_256s.h b/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_simd_utils_x86_256s.h index 5caee76a48..52a081ae9b 100644 --- a/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_simd_utils_x86_256s.h +++ b/src/gromacs/mdlib/nbnxn_kernels/nbnxn_kernel_simd_utils_x86_256s.h @@ -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)); } diff --git a/src/gromacs/topology/mtop_util.c b/src/gromacs/topology/mtop_util.c index 19fd0927dc..24eb127af2 100644 --- a/src/gromacs/topology/mtop_util.c +++ b/src/gromacs/topology/mtop_util.c @@ -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; } } diff --git a/src/programs/view/xdlg.cpp b/src/programs/view/xdlg.cpp index 4c3d4375ac..2719c42b80 100644 --- a/src/programs/view/xdlg.cpp +++ b/src/programs/view/xdlg.cpp @@ -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; } diff --git a/tests/CppCheck.cmake b/tests/CppCheck.cmake index 0f7917271f..767631b715 100644 --- a/tests/CppCheck.cmake +++ b/tests/CppCheck.cmake @@ -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/* )