From 59ebcc4efa8b46c34572a22eb31ccc59714b9dca Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Sat, 3 May 2014 12:27:14 -0400 Subject: [PATCH] Fix comparison of array to NULL 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 | 2 +- src/gromacs/gmxpreprocess/resall.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gromacs/gmxlib/gmx_detect_hardware.c b/src/gromacs/gmxlib/gmx_detect_hardware.c index 9aa1105bb3..7750b25689 100644 --- a/src/gromacs/gmxlib/gmx_detect_hardware.c +++ b/src/gromacs/gmxlib/gmx_detect_hardware.c @@ -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); } diff --git a/src/gromacs/gmxpreprocess/resall.c b/src/gromacs/gmxpreprocess/resall.c index 91aa32613a..a95fb1b27c 100644 --- a/src/gromacs/gmxpreprocess/resall.c +++ b/src/gromacs/gmxpreprocess/resall.c @@ -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); -- 2.22.0