[FFmpeg-devel] [PATCH 2/2] avformat/utils: simplify ff_alloc_extradata()

Paul B Mahol onemda at gmail.com
Tue Mar 6 16:29:59 EET 2018


On 3/6/18, James Almer <jamrial at gmail.com> wrote:
> Cosmetic refactor
>
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavformat/utils.c | 26 +++++++++++---------------
>  1 file changed, 11 insertions(+), 15 deletions(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 31340a484b..3ca1ca2441 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3243,24 +3243,20 @@ static int tb_unreliable(AVCodecContext *c)
>
>  int ff_alloc_extradata(AVCodecParameters *par, int size)
>  {
> -    int ret;
> -
>      av_freep(&par->extradata);
> -    if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
> -        par->extradata = NULL;
> -        par->extradata_size = 0;
> +    par->extradata_size = 0;
> +
> +    if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
>          return AVERROR(EINVAL);
> -    }
> +
>      par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
> -    if (par->extradata) {
> -        memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> -        par->extradata_size = size;
> -        ret = 0;
> -    } else {
> -        par->extradata_size = 0;
> -        ret = AVERROR(ENOMEM);
> -    }
> -    return ret;
> +    if (!par->extradata)
> +        return AVERROR(ENOMEM);
> +
> +    memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
> +    par->extradata_size = size;
> +
> +    return 0;
>  }
>
>  int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par,
> AVIOContext *pb, int size)
> --
> 2.16.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

lgtm


More information about the ffmpeg-devel mailing list