[FFmpeg-devel] [PATCH 2/2] avcodec/vp9.: Use av_malloc_array()

Ronald S. Bultje rsbultje at gmail.com
Mon Aug 25 20:37:05 CEST 2014


Hi,

On Mon, Aug 25, 2014 at 12:47 PM, Michael Niedermayer <michaelni at gmx.at>
wrote:

> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavcodec/vp9.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
> index 8f22685..241ea6c 100644
> --- a/libavcodec/vp9.c
> +++ b/libavcodec/vp9.c
> @@ -368,7 +368,7 @@ static int update_block_buffers(AVCodecContext *ctx)
>      if (s->uses_2pass) {
>          int sbs = s->sb_cols * s->sb_rows;
>
> -        s->b_base = av_malloc(sizeof(VP9Block) * s->cols * s->rows);
> +        s->b_base = av_malloc_array(s->cols, s->rows * sizeof(VP9Block));


How about av_malloc_array(s->cols * s->rows, sizeof(VP9Block))? Frame w/h
is 16bit limited, so rows/cols are naturally 13bits limited (since they are
in units of 8 pixels), so the product is 26bit max, so it won't overflow. I
don't even think the product of cols*rows*sizeof can overflow, but I guess
it is stylistically preferrable..

Ronald


More information about the ffmpeg-devel mailing list