Fix comparison of array to NULL
authorRoland Schulz <roland@utk.edu>
Sat, 3 May 2014 16:27:14 +0000 (12:27 -0400)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Fri, 9 May 2014 19:05:00 +0000 (21:05 +0200)
Static char array is never NULL. Detected by clang 3.5. Also fixes
output of read_atype and print error for incorrect format.

Change-Id: I834fca2d8fdd49167a88dc15bc7a2e72f4d97269

src/gromacs/gmxlib/gmx_detect_hardware.c
src/gromacs/gmxpreprocess/resall.c

index 9aa1105bb3193e79912e57e8aa9b45e714356b6f..7750b25689f9982df61440b822acb1cb4e5c28d3 100644 (file)
@@ -580,7 +580,7 @@ static void gmx_detect_gpus(FILE *fplog, const t_commrec *cr)
 
         if (detect_cuda_gpus(&hwinfo_g->gpu_info, detection_error) != 0)
         {
-            if (detection_error != NULL && detection_error[0] != '\0')
+            if (detection_error[0] != '\0')
             {
                 sprintf(sbuf, ":\n      %s\n", detection_error);
             }
index 91aa32613a2600320b8fac3efdd68e9812e7e56e..a95fb1b27caaa57cf5faa675fec95761f5b6f9c4 100644 (file)
@@ -79,20 +79,23 @@ gpp_atomtype_t read_atype(const char *ffdir, t_symtab *tab)
             /* Skip blank or comment-only lines */
             do
             {
-                fgets2(buf, STRLEN, in);
-                if (NULL != buf)
+                if (fgets2(buf, STRLEN, in) != NULL)
                 {
                     strip_comment(buf);
                     trim(buf);
                 }
             }
-            while (!feof(in) && NULL != buf && strlen(buf) == 0);
+            while (!feof(in) && strlen(buf) == 0);
 
-            if ((buf != NULL) && (sscanf(buf, "%s%lf", name, &m) == 2))
+            if (sscanf(buf, "%s%lf", name, &m) == 2)
             {
                 a->m = m;
                 add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
-                fprintf(stderr, "\rAtomtype %d", nratt+1);
+                fprintf(stderr, "\rAtomtype %d", ++nratt);
+            }
+            else
+            {
+                fprintf(stderr, "\nInvalid format: %s\n", buf);
             }
         }
         gmx_ffclose(in);