X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fh264_mp4toannexb_bsf.c;h=3b212e5a553e3c1c19e2ea28662a9acb0be64e9f;hb=849b9d34c7ef70b370c53e7af3940f51cbc07d0f;hp=86b948a31740085e1490d778653568d5566935b5;hpb=8d929afd256069aa881f2bf58ef9f0ffce2d6b7e;p=ffmpeg diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 86b948a3174..3b212e5a553 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -37,13 +37,14 @@ static int alloc_and_copy(uint8_t **poutbuf, int *poutbuf_size, { uint32_t offset = *poutbuf_size; uint8_t nal_header_size = offset ? 3 : 4; - void *tmp; + int err; *poutbuf_size += sps_pps_size + in_size + nal_header_size; - tmp = av_realloc(*poutbuf, *poutbuf_size); - if (!tmp) - return AVERROR(ENOMEM); - *poutbuf = tmp; + if ((err = av_reallocp(poutbuf, + *poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE)) < 0) { + *poutbuf_size = 0; + return err; + } if (sps_pps) memcpy(*poutbuf + offset, sps_pps, sps_pps_size); memcpy(*poutbuf + sps_pps_size + nal_header_size + offset, in, in_size); @@ -84,7 +85,7 @@ static int h264_extradata_to_annexb(AVCodecContext *avctx, const int padding) } while (unit_nb--) { - void *tmp; + int err; unit_size = AV_RB16(extradata); total_size += unit_size + 4; @@ -94,12 +95,8 @@ static int h264_extradata_to_annexb(AVCodecContext *avctx, const int padding) av_free(out); return AVERROR(EINVAL); } - tmp = av_realloc(out, total_size + padding); - if (!tmp) { - av_free(out); - return AVERROR(ENOMEM); - } - out = tmp; + if ((err = av_reallocp(&out, total_size + padding)) < 0) + return err; memcpy(out + total_size - unit_size - 4, nalu_header, 4); memcpy(out + total_size - unit_size, extradata + 2, unit_size); extradata += 2 + unit_size;