[FFmpeg-devel] [PATCH 7/8] cbs_mpeg2.c: use a while loop with a loop condition instead of an infinite loop

Scott Theisen scott.the.elm at gmail.com
Tue Feb 1 23:20:55 EET 2022


This enhances the clarity of the code.
---
 libavcodec/cbs_mpeg2.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
index 648b270f44..2b80266910 100644
--- a/libavcodec/cbs_mpeg2.c
+++ b/libavcodec/cbs_mpeg2.c
@@ -148,7 +148,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
     CodedBitstreamUnitType unit_type;
     uint32_t start_code = -1;
     size_t unit_size;
-    int err, i, final = 0;
+    int err, i = 0, final = 0;
 
     start = avpriv_find_start_code(frag->data, frag->data + frag->data_size,
                                    &start_code);
@@ -157,7 +157,7 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
         return AVERROR_INVALIDDATA;
     }
 
-    for (i = 0;; i++) {
+    while (!final) {
         unit_type = start_code & 0xff;
 
         end = avpriv_find_start_code(start--, frag->data + frag->data_size,
@@ -182,10 +182,8 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
         if (err < 0)
             return err;
 
-        if (final)
-            break;
-
         start = end;
+        i++;
     }
 
     return 0;
-- 
2.32.0



More information about the ffmpeg-devel mailing list