aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cubeit.c4
-rw-r--r--src/partialator.c8
-rw-r--r--src/process_hkl.c14
-rw-r--r--src/stream.c19
4 files changed, 37 insertions, 8 deletions
diff --git a/src/cubeit.c b/src/cubeit.c
index 51f4a57c..f85acdf3 100644
--- a/src/cubeit.c
+++ b/src/cubeit.c
@@ -393,7 +393,9 @@ static void *get_image(void *qp)
/* Get the next filename */
if ( read_chunk(qargs->fh, &image) == 1 ) {
- ERROR("Failed to read chunk from the input stream.\n");
+ if ( ferror(qargs->fh) ) {
+ ERROR("Stream read error.\n");
+ }
return NULL;
}
diff --git a/src/partialator.c b/src/partialator.c
index 0e2cfb2e..ea3eb50c 100644
--- a/src/partialator.c
+++ b/src/partialator.c
@@ -262,6 +262,10 @@ int main(int argc, char *argv[])
}
n_total_patterns = count_patterns(fh);
+ if ( n_total_patterns == 0 ) {
+ ERROR("No patterns to process.\n");
+ return 1;
+ }
STATUS("There are %i patterns to process\n", n_total_patterns);
images = malloc(n_total_patterns * sizeof(struct image));
@@ -280,7 +284,9 @@ int main(int argc, char *argv[])
Reflection *refl;
RefListIterator *iter;
- if ( read_chunk(fh, &images[i]) == 1 ) {
+ if ( read_chunk(fh, &images[i]) != 0 ) {
+ /* Should not happen, because we counted the patterns
+ * earlier. */
ERROR("Failed to read chunk from the input stream.\n");
return 1;
}
diff --git a/src/process_hkl.c b/src/process_hkl.c
index 9b7c0dcd..4dc49128 100644
--- a/src/process_hkl.c
+++ b/src/process_hkl.c
@@ -307,7 +307,7 @@ static void merge_all(FILE *fh, RefList *model,
/* Get data from next chunk */
rval = read_chunk(fh, &image);
- if ( rval ) continue;
+ if ( rval ) break;
n_patterns++;
@@ -509,6 +509,10 @@ int main(int argc, char *argv[])
/* Count the number of patterns in the file */
n_total_patterns = count_patterns(fh);
+ if ( n_total_patterns == 0 ) {
+ ERROR("No patterns to process.\n");
+ return 1;
+ }
STATUS("There are %i patterns to process\n", n_total_patterns);
rewind(fh);
@@ -536,6 +540,10 @@ int main(int argc, char *argv[])
config_startafter, config_stopafter,
sym, n_total_patterns,
hist_vals, hist_h, hist_k, hist_l, &hist_i, 1);
+ if ( ferror(fh) ) {
+ ERROR("Stream read error.\n");
+ return 1;
+ }
rewind(fh);
if ( space_for_hist && (hist_i >= space_for_hist) ) {
ERROR("Histogram array was too small!\n");
@@ -552,6 +560,10 @@ int main(int argc, char *argv[])
merge_all(fh, model, config_maxonly, config_scale, 0,
config_startafter, config_stopafter, sym, n_total_patterns,
NULL, 0, 0, 0, NULL, 2);
+ if ( ferror(fh) ) {
+ ERROR("Stream read error.\n");
+ return 1;
+ }
write_reflist(output, model, cell);
diff --git a/src/stream.c b/src/stream.c
index fd4f5c47..289d274e 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -129,6 +129,11 @@ int count_patterns(FILE *fh)
} while ( rval != NULL );
+ if ( ferror(fh) ) {
+ ERROR("Read error while counting patterns.\n");
+ return 0;
+ }
+
return n_total_patterns;
}
@@ -319,7 +324,7 @@ int read_chunk(FILE *fh, struct image *image)
rval = fgets(line, 1023, fh);
/* Trouble? */
- if ( rval == NULL ) return 1;
+ if ( rval == NULL ) break;
chomp(line);
@@ -378,12 +383,16 @@ int read_chunk(FILE *fh, struct image *image)
}
}
- } while ( strcmp(line, CHUNK_END_MARKER) != 0 );
+ if ( strcmp(line, CHUNK_END_MARKER) == 0 ) {
+ if ( have_filename && have_ev ) return 0;
+ ERROR("Incomplete chunk found in input file.\n");
+ return 1;
+ }
- if ( have_filename && have_ev ) return 0;
+ } while ( 1 );
- ERROR("Incomplete chunk found in input file.\n");
- return 1;
+ return 1; /* Either error or EOF, don't care because we will complain
+ * on the terminal if it was an error. */
}