diff --git a/tests/api/api-seek-test.c b/tests/api/api-seek-test.c
index 799187f93eb366a3725f8c5505c6b178750c8a45..cc3287b28f9e14e446a78a0ced10cf56e94e053f 100644
--- a/tests/api/api-seek-test.c
+++ b/tests/api/api-seek-test.c
@@ -248,10 +248,11 @@ static int seek_test(const char *input_filename, const char *start, const char *
         return -1;
 
     for (i = start_ts; i < end_ts; i += 100) {
-        for (j = i + 100; j < end_ts; j += 100)
-        result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, i, j, 0);
-        if (result != 0)
-            return -1;
+        for (j = i + 100; j < end_ts; j += 100) {
+            result = compute_crc_of_packets(fmt_ctx, video_stream, ctx, fr, i, j, 0);
+            if (result != 0)
+                return -1;
+        }
     }
 
     av_freep(&crc_array);