Fix problems found by cppcheck 1.56
authorRoland Schulz <roland@utk.edu>
Sun, 30 Sep 2012 19:57:59 +0000 (15:57 -0400)
committerRoland Schulz <roland@utk.edu>
Sun, 30 Sep 2012 21:42:58 +0000 (17:42 -0400)
Doesn't fix all problems. New suppressions in Jenkins for 4.6
(so that I can upgrade without having to fix all):

  --suppress=uninitvar:src/gmxlib/md5.c --suppress=nullPointer:src/mdlib/mdebin_bar.c --suppress=nullPointer:src/gmxlib/oenv.c --suppress=nullPointer:src/gmxlib/selection/selhelp.c \
  --suppress=memleak:src/tools/levenmar.c --suppress=selfAssignment:src/gmxlib/nonbonded/nb_kernel_bluegene/* \
  --suppress=invalidPointerCast:src/gmxlib/checkpoint.c --suppress=invalidPointerCast:src/gmxlib/nonbonded/nb_kernel_sse2_single/* --suppress=invalidPointerCast:src/mdlib/fftpack.c \
  --suppress=obsoleteFunctionsusleep:*.c --suppress=obsoleteFunctionsctime_r:*.c --suppress=invalidPrintfArgType_sint:*.c invalidPrintfArgType_uint:*.c

The remaining nullPointer are false positives as far as I know.
Problems found in 4.6 (haven't run cppcheck on 4.5) but
applied to 4.5 because it is also affected.

Change-Id: I5c0b4bce52a0c9ff6ef4ba51721cdf5baff42814

src/gmxlib/statutil.c
src/kernel/openmm_wrapper.cpp
src/mdlib/constr.c
src/mdlib/gmx_wallcycle.c

index fe5a161fdd0b39dc85a80e89644814123306f59a..75541029824cd99875ebf71ecca7cb86d7cd5a85 100644 (file)
@@ -253,7 +253,7 @@ int check_times(real t)
 static void set_default_time_unit(const char *time_list[], gmx_bool bCanTime)
 {
     int i,j;
-    const char *select;
+    const char *select = NULL;
 
     if (bCanTime)
     {
index 051a13a704fa9bdde6be55cabdc429b35516dedb..744f2032631621cb2bf348a6cffc54561e3852d4 100644 (file)
@@ -142,7 +142,7 @@ static void splitOptionValue(const string &s, string &opt, string &val)
                  integer less than, equal to, or greater than 0 if \p s1 less than, 
                  identical to, or greater than \p s2.
  */
-static gmx_bool isStringEqNCase(const string s1, const string s2)
+static gmx_bool isStringEqNCase(const string& s1, const string& s2)
 {
     return (gmx_strncasecmp(s1.c_str(), s2.c_str(), max(s1.length(), s2.length())) == 0);
 }
index 94abc70af7d517fe6330ee33dcf85caa4c5d86a5..7f7e3d8f30f29095705eda8bf6d64b8759bcc618 100644 (file)
@@ -160,14 +160,6 @@ static int pcomp(const void *p1, const void *p2)
     return min1-min2;
 }
 
-static int icomp(const void *p1, const void *p2)
-{
-  atom_id *a1=(atom_id *)p1;
-  atom_id *a2=(atom_id *)p2;
-
-  return (*a1)-(*a2);
-}
-
 int n_flexible_constraints(struct gmx_constr *constr)
 {
   int nflexcon;
@@ -413,7 +405,7 @@ gmx_bool constrain(FILE *fplog,gmx_bool bLog,gmx_bool bEner,
         case econqCoord:
             csettle(constr->settled,
                     nsettle,settle->iatoms,x[0],xprime[0],
-                    invdt,v[0],vir!=NULL,rmdr,&error,&vetavar);
+                    invdt,v?v[0]:NULL,vir!=NULL,rmdr,&error,&vetavar);
             inc_nrnb(nrnb,eNR_SETTLE,nsettle);
             if (v != NULL)
             {
index 8224baf55951dddc4149648b9808faca3afff9c7..3fa71b84fed28cedbc9bc4c7337f4fb14617bf3e 100644 (file)
@@ -433,7 +433,7 @@ void wallcycle_print(FILE *fplog, int nnodes, int npme, double realtime,
             if (subdivision(i))
             {
                 print_cycles(fplog,c2t,wcn[i],
-                             (i>=ewcPMEMESH || i<=ewcPME_SOLVE) ? npme : npp,
+                             (i>=ewcPMEMESH && i<=ewcPME_SOLVE) ? npme : npp,
                              wc->wcc[i].n,cycles[i],tot);
             }
         }