diff mbox series

[FFmpeg-devel,4/9] avcodec/mpegpicture: Remove always-true checks

Message ID DB6PR0101MB22145F563887E3716BAA4EA48F629@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 3d5a74cc3899df9d1f0b215b03bfddd1c8226f04
Headers show
Series [FFmpeg-devel,1/9] avcodec/wmv2dec: Zero mb_type array for I pictures | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Aug. 9, 2022, 6:34 p.m. UTC
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@outlook.com>
---
 libavcodec/mpegpicture.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

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;