---
libavcodec/binkaudio.c | 9 +++++----
libavcodec/bitstream.c | 9 +++++----
libavcodec/flashsv.c | 10 ++++++----
libavcodec/g2meet.c | 9 ++++-----
libavcodec/h264_mp4toannexb_bsf.c | 20 +++++++-------------
libavcodec/libmp3lame.c | 10 +++-------
libavcodec/libschroedingerenc.c | 7 +++++--
libavcodec/libtheoraenc.c | 10 ++++++----
libavcodec/libvpxenc.c | 9 +++++----
libavcodec/shorten.c | 27 ++++++++++-----------------
libavcodec/utils.c | 2 +-
libavcodec/zmbv.c | 15 +++++++--------
12 files changed, 64 insertions(+), 73 deletions(-)
diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index d49964b..8c8b722 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -294,6 +294,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
if (!get_bits_left(gb)) {
uint8_t *buf;
+ int err;
/* handle end-of-stream */
if (!avpkt->size) {
*got_frame_ptr = 0;
@@ -303,10 +304,10 @@ static int decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
return AVERROR_INVALIDDATA;
}
- buf = av_realloc(s->packet_buffer, avpkt->size +
FF_INPUT_BUFFER_PADDING_SIZE);
- if (!buf)
- return AVERROR(ENOMEM);
- s->packet_buffer = buf;
+ if ((err = av_reallocp(&s->packet_buffer,
+ avpkt->size +
+ FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
+ return err;
memcpy(s->packet_buffer, avpkt->data, avpkt->size);
init_get_bits(gb, s->packet_buffer, avpkt->size * 8);
consumed = avpkt->size;
diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
index 197e07f..1193afa 100644
--- a/libavcodec/bitstream.c
+++ b/libavcodec/bitstream.c
@@ -102,16 +102,17 @@ void avpriv_copy_bits(PutBitContext *pb, const uint8_t
*src, int length)
static int alloc_table(VLC *vlc, int size, int use_static)
{
- int index = vlc->table_size;
+ int index = vlc->table_size, err;
vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
if (use_static)
return AVERROR_BUG;
vlc->table_allocated += (1 << vlc->bits);
- vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 *
vlc->table_allocated);
- if (!vlc->table)
- return AVERROR(ENOMEM);
+ if ((err = av_reallocp(&vlc->table,
+ sizeof(VLC_TYPE) * 2 *
+ vlc->table_allocated)) < 0)
+ return err;
}
return index;
}
diff --git a/libavcodec/flashsv.c b/libavcodec/flashsv.c
index 2fbe221..ff74e23 100644
--- a/libavcodec/flashsv.c
+++ b/libavcodec/flashsv.c
@@ -317,11 +317,13 @@ static int flashsv_decode_frame(AVCodecContext *avctx,
void *data,
/* we care for keyframes only in Screen Video v2 */
s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);
if (s->is_keyframe) {
- s->keyframedata = av_realloc(s->keyframedata, avpkt->size);
+ int err;
+ if ((err = av_reallocp(&s->keyframedata, avpkt->size)) < 0)
+ return err;
memcpy(s->keyframedata, avpkt->data, avpkt->size);
- s->blocks = av_realloc(s->blocks,
- (v_blocks + !!v_part) * (h_blocks + !!h_part)
- * sizeof(s->blocks[0]));
+ if ((err = av_reallocp(&s->blocks, (v_blocks + !!v_part) *
+ (h_blocks + !!h_part) * sizeof(s->blocks[0])))
< 0)
+ return err;
}
av_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n",
diff --git a/libavcodec/g2meet.c b/libavcodec/g2meet.c
index 1bbac2d..c659101 100644
--- a/libavcodec/g2meet.c
+++ b/libavcodec/g2meet.c
@@ -236,16 +236,15 @@ static int jpg_decode_data(JPGContext *c, int width, int
height,
int swapuv)
{
GetBitContext gb;
- uint8_t *tmp;
int mb_w, mb_h, mb_x, mb_y, i, j;
int bx, by;
int unesc_size;
int ret;
- tmp = av_realloc(c->buf, src_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!tmp)
- return AVERROR(ENOMEM);
- c->buf = tmp;
+ if ((ret = av_reallocp(&c->buf,
+ src_size +
+ FF_INPUT_BUFFER_PADDING_SIZE)) < 0)
+ return ret;
jpg_unescape(src, src_size, c->buf, &unesc_size);
memset(c->buf + unesc_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
init_get_bits(&gb, c->buf, unesc_size * 8);
diff --git a/libavcodec/h264_mp4toannexb_bsf.c
b/libavcodec/h264_mp4toannexb_bsf.c
index e86c3e1..b67e3e8 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -37,13 +37,12 @@ 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 + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!tmp)
- return AVERROR(ENOMEM);
- *poutbuf = tmp;
+ if ((err = av_reallocp(poutbuf,
+ *poutbuf_size + FF_INPUT_BUFFER_PADDING_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,8 +83,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;
if (total_size > INT_MAX - padding ||
@@ -94,12 +92,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;
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index 5e7caf8..c7e759f 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -57,18 +57,14 @@ typedef struct LAMEContext {
static int realloc_buffer(LAMEContext *s)
{
if (!s->buffer || s->buffer_size - s->buffer_index < BUFFER_SIZE) {
- uint8_t *tmp;
- int new_size = s->buffer_index + 2 * BUFFER_SIZE;
+ int new_size = s->buffer_index + 2 * BUFFER_SIZE, int err;
av_dlog(s->avctx, "resizing output buffer: %d -> %d\n", s->buffer_size,
new_size);
- tmp = av_realloc(s->buffer, new_size);
- if (!tmp) {
- av_freep(&s->buffer);
+ if ((err = av_reallocp(&s->buffer, new_size)) < 0) {
s->buffer_size = s->buffer_index = 0;
- return AVERROR(ENOMEM);
+ return err;
}
- s->buffer = tmp;
s->buffer_size = new_size;
}
return 0;
diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c
index 210dd34..e56c36e 100644
--- a/libavcodec/libschroedingerenc.c
+++ b/libavcodec/libschroedingerenc.c
@@ -296,6 +296,7 @@ static int libschroedinger_encode_frame(AVCodecContext
*avctx, AVPacket *pkt,
/* Now check to see if we have any output from the encoder. */
while (go) {
+ int err;
SchroStateEnum state;
state = schro_encoder_wait(encoder);
switch (state) {
@@ -310,8 +311,10 @@ static int libschroedinger_encode_frame(AVCodecContext
*avctx, AVPacket *pkt,
* be able to set the pts correctly. So we don't write data
* to the frame output queue until we actually have a frame
*/
- p_schro_params->enc_buf = av_realloc(p_schro_params->enc_buf,
- p_schro_params->enc_buf_size
+ enc_buf->length);
+ if ((err = av_reallocp(&p_schro_params->enc_buf,
+ p_schro_params->enc_buf_size +
+ enc_buf->length)) < 0)
+ return err;
memcpy(p_schro_params->enc_buf + p_schro_params->enc_buf_size,
enc_buf->data, enc_buf->length);
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 3990692..560e16d 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -58,7 +58,6 @@ static int concatenate_packet(unsigned int* offset,
const ogg_packet* packet)
{
const char* message = NULL;
- uint8_t* newdata = NULL;
int newsize = avc_context->extradata_size + 2 + packet->bytes;
if (packet->bytes < 0) {
@@ -68,16 +67,19 @@ static int concatenate_packet(unsigned int* offset,
} else if (newsize < avc_context->extradata_size) {
message = "extradata_size would overflow";
} else {
- newdata = av_realloc(avc_context->extradata, newsize);
- if (!newdata)
+ int err;
+ if ((err = av_reallocp(&avc_context->extradata, newsize)) < 0) {
message = "av_realloc failed";
+ av_log(avc_context, AV_LOG_ERROR,
+ "concatenate_packet failed: %s\n", message);
+ return err;
+
}
if (message) {
av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n",
message);
return -1;
}
- avc_context->extradata = newdata;
avc_context->extradata_size = newsize;
AV_WB16(avc_context->extradata + (*offset), packet->bytes);
*offset += 2;
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 0ecc2f9..e65f63a 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -467,11 +467,12 @@ static int queue_frames(AVCodecContext *avctx, AVPacket
*pkt_out,
break;
case VPX_CODEC_STATS_PKT: {
struct vpx_fixed_buf *stats = &ctx->twopass_stats;
- stats->buf = av_realloc(stats->buf,
- stats->sz + pkt->data.twopass_stats.sz);
- if (!stats->buf) {
+ int err;
+ if ((err = av_reallocp(&stats->buf,
+ stats->sz +
+ pkt->data.twopass_stats.sz)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
- return AVERROR(ENOMEM);
+ return err;
}
memcpy((uint8_t*)stats->buf + stats->sz,
pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index c394c52..f777fe9 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -119,9 +119,7 @@ static av_cold int shorten_decode_init(AVCodecContext
*avctx)
static int allocate_buffers(ShortenContext *s)
{
- int i, chan;
- int *coeffs;
- void *tmp_ptr;
+ int i, chan, err;
for (chan = 0; chan < s->channels; chan++) {
if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
@@ -135,26 +133,21 @@ static int allocate_buffers(ShortenContext *s)
return AVERROR_INVALIDDATA;
}
- tmp_ptr =
- av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean));
- if (!tmp_ptr)
- return AVERROR(ENOMEM);
- s->offset[chan] = tmp_ptr;
+ if ((err = av_reallocp(&s->offset[chan],
+ sizeof(s->offset[chan]) *
+ FFMAX(1, s->nmean))) < 0)
+ return err;
- tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) *
- sizeof(s->decoded_base[0][0]));
- if (!tmp_ptr)
- return AVERROR(ENOMEM);
- s->decoded_base[chan] = tmp_ptr;
+ if ((err = av_reallocp(&s->decoded_base[chan], (s->blocksize +
s->nwrap) *
+ sizeof(s->decoded_base[0][0]))) < 0)
+ return err;
for (i = 0; i < s->nwrap; i++)
s->decoded_base[chan][i] = 0;
s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
}
- coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
- if (!coeffs)
- return AVERROR(ENOMEM);
- s->coeffs = coeffs;
+ if ((err = av_reallocp(&s->coeffs, s->nwrap * sizeof(*s->coeffs))) < 0)
+ return err;
return 0;
}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index bf79cf1..0eeecd2 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -62,7 +62,7 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t
min_size)
min_size = FFMAX(17 * min_size / 16 + 32, min_size);
- ptr = av_realloc(ptr, min_size);
+ av_reallocp(&ptr, min_size);
/* we could set this to the unmodified min_size but this is safer
* if the user lost the ptr and uses NULL now
*/
diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c
index 65fa5ff..a3e2401 100644
--- a/libavcodec/zmbv.c
+++ b/libavcodec/zmbv.c
@@ -417,6 +417,7 @@ static int decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPac
c->flags = buf[0];
buf++; len--;
if (c->flags & ZMBV_KEYFRAME) {
+ int err;
hi_ver = buf[0];
lo_ver = buf[1];
c->comp = buf[2];
@@ -481,14 +482,12 @@ static int decode_frame(AVCodecContext *avctx, void
*data, int *got_frame, AVPac
return AVERROR_UNKNOWN;
}
- tmp = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8));
- if (!tmp)
- return AVERROR(ENOMEM);
- c->cur = tmp;
- tmp = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8));
- if (!tmp)
- return AVERROR(ENOMEM);
- c->prev = tmp;
+ if ((err = av_reallocp(&c->cur, avctx->width * avctx->height *
+ (c->bpp / 8))) < 0)
+ return err;
+ if ((err = av_reallocp(&c->prev, avctx->width * avctx->height *
+ (c->bpp / 8))) < 0)
+ return err;
c->bx = (c->width + c->bw - 1) / c->bw;
c->by = (c->height + c->bh - 1) / c->bh;
}
--
1.7.10.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel