Avoid undefined behavior in overflow check
authorMichael McConville <mmcco@mykolab.com>
Thu, 11 Feb 2016 00:29:18 +0000 (19:29 -0500)
committerGuy Harris <guy@alum.mit.edu>
Thu, 11 Feb 2016 01:39:48 +0000 (01:39 +0000)
Signed overflow is undefined, so testing for overflow with
"if (i + 1 < i)" is itself undefined. Because this instance is an
increment, we can just test against G_MAXINT.

Change-Id: Ib8b7c23ec362d5637125fcf6457ea9423fedf0e1
Reviewed-on: https://code.wireshark.org/review/13896
Reviewed-by: Guy Harris <guy@alum.mit.edu>
wiretap/merge.c

index 19c11cd5778b3cd4358230012c14a904301ac93f..06dc5db6178bab4c8f3e763f934fb0a5a3b71b6a 100644 (file)
@@ -148,7 +148,7 @@ merge_open_in_files(int in_file_count, const char *const *in_file_names,
         }
         size = wtap_file_size(files[i].wth, err);
         if (size == -1) {
-            for (j = 0; j + 1 > j && j <= i; j++)
+            for (j = 0; j != G_MAXINT && j <= i; j++)
                 cleanup_in_file(&files[j]);
             *err_fileno = i;
             return FALSE;