[FFmpeg-cvslog] avcodec/mpegpicture: Remove always-true checks

Andreas Rheinhardt git at videolan.org
Fri Aug 12 04:23:41 EEST 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Aug  8 10:42:32 2022 +0200| [3d5a74cc3899df9d1f0b215b03bfddd1c8226f04] | committer: Andreas Rheinhardt

avcodec/mpegpicture: Remove always-true checks

Of all the buffers that are made writable, three are always allocated
and the other four are allocated iff any one of them is allocated;
so one can replace the seven checks for existence with one.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3d5a74cc3899df9d1f0b215b03bfddd1c8226f04
---

 libavcodec/mpegpicture.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index f32f8d061b..dc79662143 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -49,21 +49,22 @@ static void av_noinline free_picture_tables(Picture *pic)
 
 static int make_tables_writable(Picture *pic)
 {
-    int ret, i;
 #define MAKE_WRITABLE(table) \
 do {\
-    if (pic->table &&\
-       (ret = av_buffer_make_writable(&pic->table)) < 0)\
-    return ret;\
+    int ret = av_buffer_make_writable(&pic->table); \
+    if (ret < 0) \
+        return ret; \
 } while (0)
 
     MAKE_WRITABLE(mbskip_table_buf);
     MAKE_WRITABLE(qscale_table_buf);
     MAKE_WRITABLE(mb_type_buf);
 
-    for (i = 0; i < 2; i++) {
-        MAKE_WRITABLE(motion_val_buf[i]);
-        MAKE_WRITABLE(ref_index_buf[i]);
+    if (pic->motion_val_buf[0]) {
+        for (int i = 0; i < 2; i++) {
+            MAKE_WRITABLE(motion_val_buf[i]);
+            MAKE_WRITABLE(ref_index_buf[i]);
+        }
     }
 
     return 0;



More information about the ffmpeg-cvslog mailing list