On an I/O error, merge_read_packet() and merge_append_read_packet() need
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 21 Nov 2011 06:26:03 +0000 (06:26 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Mon, 21 Nov 2011 06:26:03 +0000 (06:26 +0000)
to return a pointer to the merge_in_file_t that got the error.  Set *err
to 0 on success and an error code on an err, treat a null return as an
EOF indication, and if we don't get a null return check for a non-zero
error code and treat that as an I/O error.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@39964 f5534014-38df-0310-8fa8-9805f1628bb7

file.c
merge.c
mergecap.c

diff --git a/file.c b/file.c
index e3db476df3ac2be997c9e943a7836f81394908eb..f6b9af91d813217276b989d6380a98ebe09042a8 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1290,8 +1290,13 @@ cf_merge_files(char **out_filenamep, int in_file_count,
       in_file = merge_read_packet(in_file_count, in_files, &read_err,
                                   &err_info);
     if (in_file == NULL) {
-      if (read_err != 0)
-        got_read_error = TRUE;
+      /* EOF */
+      break;
+    }
+
+    if (read_err != 0) {
+      /* I/O error reading from in_file */
+      got_read_error = TRUE;
       break;
     }
 
diff --git a/merge.c b/merge.c
index a489fc233aeb21976e463e27fa8e4b43ac43a9f6..95be037fcfcca3acb7a154dc529d0fef721a4c06 100644 (file)
--- a/merge.c
+++ b/merge.c
@@ -150,9 +150,16 @@ is_earlier(struct wtap_nstime *l, struct wtap_nstime *r) {
 
 /*
  * Read the next packet, in chronological order, from the set of files
- * to be merged.  Return a pointer to the merge_in_file_t for the file
- * from which the packet was read on success, or NULL on EOF or error.
- * On EOF, *err is 0; on an error, it's an error code.
+ * to be merged.
+ *
+ * On success, set *err to 0 and return a pointer to the merge_in_file_t
+ * for the file from which the packet was read.
+ *
+ * On a read error, set *err to the error and return a pointer to the
+ * merge_in_file_t for the file on which we got an error.
+ *
+ * On an EOF (meaning all the files are at EOF), set *err to 0 and return
+ * NULL.
  */
 merge_in_file_t *
 merge_read_packet(int in_file_count, merge_in_file_t in_files[],
@@ -211,9 +218,16 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[],
 
 /*
  * Read the next packet, in file sequence order, from the set of files
- * to be merged.  Return a pointer to the merge_in_file_t for the file
- * from which the packet was read on success, or NULL on EOF or error.
- * On EOF, *err is 0; on an error, it's an error code.
+ * to be merged.
+ *
+ * On success, set *err to 0 and return a pointer to the merge_in_file_t
+ * for the file from which the packet was read.
+ *
+ * On a read error, set *err to the error and return a pointer to the
+ * merge_in_file_t for the file on which we got an error.
+ *
+ * On an EOF (meaning all the files are at EOF), set *err to 0 and return
+ * NULL.
  */
 merge_in_file_t *
 merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
@@ -232,7 +246,7 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
     if (*err != 0) {
       /* Read error - quit immediately. */
       in_files[i].state = GOT_ERROR;
-      return NULL;
+      return &in_files[i];
     }
     /* EOF - flag this file as being at EOF, and try the next one. */
     in_files[i].state = AT_EOF;
@@ -244,5 +258,6 @@ merge_append_read_packet(int in_file_count, merge_in_file_t in_files[],
   }
 
   /* Return the ordinal of the file from which the packet was read. */
+  *err = 0;
   return &in_files[i];
 }
index 51e64464c88d5b0d5633829751c13455286c3a93..91b956d3d8c759a9957d423ccddc4bcfc48b6732 100644 (file)
@@ -351,8 +351,13 @@ main(int argc, char *argv[])
       in_file = merge_read_packet(in_file_count, in_files, &read_err,
                                   &err_info);
     if (in_file == NULL) {
-      if (read_err != 0)
-        got_read_error = TRUE;
+      /* EOF */
+      break;
+    }
+
+    if (read_err != 0) {
+      /* I/O error reading from in_file */
+      got_read_error = TRUE;
       break;
     }