[FFmpeg-devel] [PATCH 3/6] avcodec/h264_refs: Rewrite code to make control flow clearer

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Mar 27 03:38:16 EET 2024


While this change IMO makes the control flow clearer
for the human reader, it is especially important for
GCC: It erroneously believes that it is possible to
enter the SHORT2(UNUSED|LONG) cases without having
entered the preceding block that initializes pic,
frame_num, structure and j; it would emit -Wmaybe-uninitialized
warnings for these variables if they were not pseudo-
initialized with av_uninit(). This patch allows to remove
the latter.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/h264_refs.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 9bc7b20988..c2ba4b9b9e 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -646,8 +646,9 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
             av_log(h->avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode,
                    h->mmco[i].short_pic_num, h->mmco[i].long_arg);
 
-        if (mmco[i].opcode == MMCO_SHORT2UNUSED ||
-            mmco[i].opcode == MMCO_SHORT2LONG) {
+        switch (mmco[i].opcode) {
+        case MMCO_SHORT2UNUSED:
+        case MMCO_SHORT2LONG:
             frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure);
             pic       = find_short(h, frame_num, &j);
             if (!pic) {
@@ -659,16 +660,12 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
                 }
                 continue;
             }
-        }
-
-        switch (mmco[i].opcode) {
-        case MMCO_SHORT2UNUSED:
-            if (h->avctx->debug & FF_DEBUG_MMCO)
-                av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n",
-                       h->mmco[i].short_pic_num, h->short_ref_count);
-            remove_short(h, frame_num, structure ^ PICT_FRAME);
-            break;
-        case MMCO_SHORT2LONG:
+            if (mmco[i].opcode == MMCO_SHORT2UNUSED) {
+                if (h->avctx->debug & FF_DEBUG_MMCO)
+                    av_log(h->avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n",
+                           h->mmco[i].short_pic_num, h->short_ref_count);
+                remove_short(h, frame_num, structure ^ PICT_FRAME);
+            } else {
                 if (h->long_ref[mmco[i].long_arg] != pic)
                     remove_long(h, mmco[i].long_arg, 0);
 
@@ -678,6 +675,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h)
                     h->long_ref[mmco[i].long_arg]->long_ref = 1;
                     h->long_ref_count++;
                 }
+            }
             break;
         case MMCO_LONG2UNUSED:
             j   = pic_num_extract(h, mmco[i].long_arg, &structure);
-- 
2.40.1



More information about the ffmpeg-devel mailing list