diff options
author | Thomas White <taw@physics.org> | 2017-10-23 15:53:19 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2017-10-23 16:01:37 +0200 |
commit | 45038c42847476ce1aee5b09c47fb330a0108cd6 (patch) | |
tree | 3979667c80cacc3bd34d0f59fc905a0d4c0b3d0d /libcrystfel/src | |
parent | 7b6fa15e761ec0c5ae9010dc21786a1a3dda7076 (diff) |
Check return values from fread/fgets
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/dirax.c | 9 | ||||
-rw-r--r-- | libcrystfel/src/felix.c | 9 | ||||
-rw-r--r-- | libcrystfel/src/mosflm.c | 16 | ||||
-rw-r--r-- | libcrystfel/src/xds.c | 11 |
4 files changed, 29 insertions, 16 deletions
diff --git a/libcrystfel/src/dirax.c b/libcrystfel/src/dirax.c index 488eb7db..512a61e1 100644 --- a/libcrystfel/src/dirax.c +++ b/libcrystfel/src/dirax.c @@ -660,9 +660,12 @@ const char *dirax_probe(UnitCell *cell) } fh = fdopen(pty, "r"); - fgets(line, 1024, fh); - if ( strncmp(line, "dirax", 5) == 0 ) { - ok = 1; + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for DirAx\n"); + } else { + if ( strncmp(line, "dirax", 5) == 0 ) { + ok = 1; + } } fclose(fh); diff --git a/libcrystfel/src/felix.c b/libcrystfel/src/felix.c index cf7a38e8..79252b2b 100644 --- a/libcrystfel/src/felix.c +++ b/libcrystfel/src/felix.c @@ -757,9 +757,12 @@ const char *felix_probe(UnitCell *cell) } fh = fdopen(pty, "r"); - fgets(line, 1024, fh); - if ( strncmp(line, "Felix", 5) == 0 ) { - ok = 1; + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for Felix\n"); + } else { + if ( strncmp(line, "Felix", 5) == 0 ) { + ok = 1; + } } fclose(fh); diff --git a/libcrystfel/src/mosflm.c b/libcrystfel/src/mosflm.c index 14cd9d96..7ebf6e19 100644 --- a/libcrystfel/src/mosflm.c +++ b/libcrystfel/src/mosflm.c @@ -896,12 +896,16 @@ const char *mosflm_probe(UnitCell *cell) for ( l=0; l<10; l++ ) { char *pos; - fgets(line, 1024, fh); - pos = strstr(line, "Mosflm version "); - if ( pos != NULL ) { - char *vers = pos+15; - ok = 1; - chop_word(vers); + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for Mosflm\n"); + } else { + pos = strstr(line, "Mosflm version "); + if ( pos != NULL ) { + char *vers = pos+15; + ok = 1; + chop_word(vers); + /* FIXME: Set capabilities based on version */ + } } } diff --git a/libcrystfel/src/xds.c b/libcrystfel/src/xds.c index bd98aec4..bfb977ea 100644 --- a/libcrystfel/src/xds.c +++ b/libcrystfel/src/xds.c @@ -679,10 +679,13 @@ const char *xds_probe(UnitCell *cell) for ( l=0; l<10; l++ ) { char *pos; - fgets(line, 1024, fh); - pos = strstr(line, "** XDS **"); - if ( pos != NULL ) { - ok = 1; + if ( fgets(line, 1024, fh) == NULL ) { + ERROR("Failed to probe for XDS\n"); + } else { + pos = strstr(line, "** XDS **"); + if ( pos != NULL ) { + ok = 1; + } } } |