diff mbox

[FFmpeg-devel,2/8] avcodec/imgconvert: remove access of AV_PIX_FMT_NB

Message ID 20191230135419.56529-2-quinkblack@foxmail.com
State New
Headers show

Commit Message

zhilizhao Dec. 30, 2019, 1:54 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

Fix av_pix_fmt_desc_get return value check.
---
 libavcodec/imgconvert.c       | 5 +++--
 libavcodec/tests/imgconvert.c | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 1fd636c83d..fb0222cdf1 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -112,7 +112,7 @@  int av_picture_crop(AVPicture *dst, const AVPicture *src,
     int x_shift;
     int max_step[4];
 
-    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
+    if (!desc)
         return -1;
 
     y_shift = desc->log2_chroma_h;
@@ -147,8 +147,9 @@  int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width,
     int i, y;
     int max_step[4];
 
-    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
+    if (!desc) {
         return -1;
+    }
 
     if (!is_yuv_planar(desc)) {
         if (src)
diff --git a/libavcodec/tests/imgconvert.c b/libavcodec/tests/imgconvert.c
index aefc324bf5..79ac654f18 100644
--- a/libavcodec/tests/imgconvert.c
+++ b/libavcodec/tests/imgconvert.c
@@ -27,8 +27,9 @@  int main(void){
     int i;
     int err=0;
     int skip = 0;
+    int fmt_count = av_pix_fmt_total_count();
 
-    for (i=0; i<AV_PIX_FMT_NB*2; i++) {
+    for (i = 0; i< fmt_count * 2; i++) {
         const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
         if(!desc || !desc->name) {
             skip ++;