diff mbox

[FFmpeg-devel,v2] avutil/frame: Use av_realloc_array()

Message ID 20191224005612.28334-1-lance.lmwang@gmail.com
State Superseded
Headers show

Commit Message

Limin Wang Dec. 24, 2019, 12:56 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavutil/frame.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Michael Niedermayer Dec. 25, 2019, 5:07 p.m. UTC | #1
On Tue, Dec 24, 2019 at 08:56:12AM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavutil/frame.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index e4038096c2..1a67eda91d 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -693,14 +693,11 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
>  {
>      AVFrameSideData *ret, **tmp;
>  
> -    if (!buf)
> +    if (!buf || frame->nb_side_data > INT_MAX - 1)
>          return NULL;
>  
> -    if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
> -        return NULL;
> -
> -    tmp = av_realloc(frame->side_data,
> -                     (frame->nb_side_data + 1) * sizeof(*frame->side_data));
> +    tmp = av_realloc_array(frame->side_data,
> +                     (frame->nb_side_data + 1), sizeof(*frame->side_data));

the () is unneeded

[...]
diff mbox

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index e4038096c2..1a67eda91d 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -693,14 +693,11 @@  AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame,
 {
     AVFrameSideData *ret, **tmp;
 
-    if (!buf)
+    if (!buf || frame->nb_side_data > INT_MAX - 1)
         return NULL;
 
-    if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
-        return NULL;
-
-    tmp = av_realloc(frame->side_data,
-                     (frame->nb_side_data + 1) * sizeof(*frame->side_data));
+    tmp = av_realloc_array(frame->side_data,
+                     (frame->nb_side_data + 1), sizeof(*frame->side_data));
     if (!tmp)
         return NULL;
     frame->side_data = tmp;