avformat/utils: simplify ff_alloc_extradata()

Cosmetic refactor

Reviewed-by: 74a2fa708af88d225ed708af758f236f869b1a57
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2018-03-06 01:37:21 -03:00
parent 0ca33b1d4e
commit 2aa42fac77
1 changed files with 11 additions and 15 deletions

View File

@ -3243,24 +3243,20 @@ static int tb_unreliable(AVCodecContext *c)
int ff_alloc_extradata(AVCodecParameters *par, int size) int ff_alloc_extradata(AVCodecParameters *par, int size)
{ {
int ret;
av_freep(&par->extradata); 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); return AVERROR(EINVAL);
}
par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
if (par->extradata) { if (!par->extradata)
return AVERROR(ENOMEM);
memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
par->extradata_size = size; par->extradata_size = size;
ret = 0;
} else { return 0;
par->extradata_size = 0;
ret = AVERROR(ENOMEM);
}
return ret;
} }
int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb, int size) int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb, int size)