ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: [Wireshark-dev] Fix signed overflow

From: Michael McConville <mmcco@xxxxxxxxxxx>
Date: Wed, 10 Feb 2016 10:46:02 -0500
Signed overflow is undefined, so the overflow check below is technically
meaningless. Because we're only checking whether an increment will
overflow, we can compare j to G_MAXINT instead.

Thanks for your time,
Michael


diff --git a/wiretap/merge.c b/wiretap/merge.c
index 19c11cd..06dc5db 100644
--- a/wiretap/merge.c
+++ b/wiretap/merge.c
@@ -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;