---
libavformat/asfenc.c | 5 ++---
libavformat/avidec.c | 4 ++--
libavformat/avienc.c | 4 ++--
libavformat/aviobuf.c | 4 ++--
libavformat/bmv.c | 5 ++---
libavformat/concat.c | 7 +++----
libavformat/gxfenc.c | 14 ++++++++------
libavformat/matroskadec.c | 21 +++++++++------------
libavformat/matroskaenc.c | 10 ++++++----
libavformat/mmst.c | 8 ++------
libavformat/mov.c | 43 ++++++++++++++++++++-----------------------
libavformat/movenchint.c | 8 +++-----
12 files changed, 61 insertions(+), 72 deletions(-)
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index a523b3a..f5d5845 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -789,9 +789,8 @@ static int asf_write_packet(AVFormatContext *s, AVPacket
*pkt)
for (i = asf->nb_index_count; i < start_sec; i++) {
if (i >= asf->nb_index_memory_alloc) {
asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;
- asf->index_ptr = (ASFIndex
*)av_realloc(asf->index_ptr,
-
sizeof(ASFIndex) *
-
asf->nb_index_memory_alloc);
+ if (av_reallocp_array(&asf->index_ptr,
asf->nb_index_memory_alloc, sizeof(ASFIndex)) < 0)
+ return AVERROR(ENOMEM);
}
// store
asf->index_ptr[i].packet_number = (uint32_t)packet_st;
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index cf24e8c..2a57a92 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -614,8 +614,8 @@ static int avi_read_header(AVFormatContext *s)
if(st->codec->codec_tag==0 && st->codec->height > 0 &&
st->codec->extradata_size < 1U<<30){
st->codec->extradata_size+= 9;
- st->codec->extradata= av_realloc(st->codec->extradata,
st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
- if(st->codec->extradata)
+ st->codec->extradata =
av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
+ if (st->codec->extradata)
memcpy(st->codec->extradata +
st->codec->extradata_size - 9, "BottomUp", 9);
}
st->codec->height= FFABS(st->codec->height);
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 9d1f510..9bc4dc7 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -537,9 +537,9 @@ static int avi_write_packet(AVFormatContext *s, AVPacket
*pkt)
int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
if (idx->ents_allocated <= idx->entry) {
- idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
+ av_reallocp(&idx->cluster, (cl + 1) * sizeof(void*));
if (!idx->cluster)
- return -1;
+ return AVERROR(ENOMEM);
idx->cluster[cl] =
av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry));
if (!idx->cluster[cl])
return -1;
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index d2eaf36..3f37671 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -867,8 +867,8 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int
buf_size)
}
if (new_allocated_size > d->allocated_size) {
- d->buffer = av_realloc(d->buffer, new_allocated_size);
- if(d->buffer == NULL)
+ av_reallocp(&d->buffer, new_allocated_size);
+ if (!d->buffer)
return AVERROR(ENOMEM);
d->allocated_size = new_allocated_size;
}
diff --git a/libavformat/bmv.c b/libavformat/bmv.c
index ce157e8..a84a6ad 100644
--- a/libavformat/bmv.c
+++ b/libavformat/bmv.c
@@ -85,10 +85,9 @@ static int bmv_read_packet(AVFormatContext *s, AVPacket *pkt)
c->size = avio_rl24(s->pb);
if (!c->size)
return AVERROR_INVALIDDATA;
- tmp = av_realloc(c->packet, c->size + 1);
- if (!tmp)
+ av_reallocp(&c->packet, c->size + 1);
+ if (!c->packet)
return AVERROR(ENOMEM);
- c->packet = tmp;
c->packet[0] = type;
if (avio_read(s->pb, c->packet + 1, c->size) != c->size)
return AVERROR(EIO);
diff --git a/libavformat/concat.c b/libavformat/concat.c
index 24c50c1..30dceee 100644
--- a/libavformat/concat.c
+++ b/libavformat/concat.c
@@ -56,7 +56,7 @@ static av_cold int concat_close(URLContext *h)
static av_cold int concat_open(URLContext *h, const char *uri, int flags)
{
- char *node_uri = NULL, *tmp_uri;
+ char *node_uri = NULL;
int err = 0;
int64_t size;
size_t len, i;
@@ -85,11 +85,10 @@ static av_cold int concat_open(URLContext *h, const char
*uri, int flags)
for (i = 0; *uri; i++) {
/* parsing uri */
len = strcspn(uri, AV_CAT_SEPARATOR);
- if (!(tmp_uri = av_realloc(node_uri, len+1))) {
+ if (err = av_reallocp(&node_uri, len + 1) < 0) {
err = AVERROR(ENOMEM);
break;
} else
- node_uri = tmp_uri;
av_strlcpy(node_uri, uri, len+1);
uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
@@ -114,7 +113,7 @@ static av_cold int concat_open(URLContext *h, const char
*uri, int flags)
if (err < 0)
concat_close(h);
- else if (!(nodes = av_realloc(nodes, data->length * sizeof(*nodes)))) {
+ else if (err = av_reallocp(&nodes, data->length * sizeof(*nodes)) < 0) {
concat_close(h);
err = AVERROR(ENOMEM);
} else
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index 128122f..19598ac 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -342,11 +342,12 @@ static int gxf_write_map_packet(AVFormatContext *s, int
rewrite)
if (!rewrite) {
if (!(gxf->map_offsets_nb % 30)) {
- gxf->map_offsets = av_realloc(gxf->map_offsets,
-
(gxf->map_offsets_nb+30)*sizeof(*gxf->map_offsets));
+ av_reallocp_array(&gxf->map_offsets, gxf->map_offsets_nb + 30,
+ sizeof(*gxf->map_offsets));
if (!gxf->map_offsets) {
+ gxf->map_offsets_nb = 0;
av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n");
- return -1;
+ return AVERROR(ENOMEM);
}
}
gxf->map_offsets[gxf->map_offsets_nb++] = pos; // do not increment here
@@ -873,11 +874,12 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket
*pkt)
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (!(gxf->flt_entries_nb % 500)) {
- gxf->flt_entries = av_realloc(gxf->flt_entries,
-
(gxf->flt_entries_nb+500)*sizeof(*gxf->flt_entries));
+ av_reallocp_array(&gxf->flt_entries, (gxf->flt_entries_nb + 500),
+ sizeof(*gxf->flt_entries));
if (!gxf->flt_entries) {
+ gxf->flt_entries_nb = 0;
av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n");
- return -1;
+ return AVERROR(ENOMEM);
}
}
gxf->flt_entries[gxf->flt_entries_nb++] = packet_start_offset;
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 9b116b0..47de254 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -878,15 +878,15 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
uint32_t id = syntax->id;
uint64_t length;
int res;
- void *newelem;
data = (char *)data + syntax->data_offset;
if (syntax->list_elem_size) {
EbmlList *list = data;
- newelem = av_realloc(list->elem,
(list->nb_elem+1)*syntax->list_elem_size);
- if (!newelem)
+ av_reallocp_array(&list->elem, list->nb_elem + 1,
syntax->list_elem_size);
+ if (!list->elem) {
+ list->nb_elem = 0;
return AVERROR(ENOMEM);
- list->elem = newelem;
+ }
data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
memset(data, 0, syntax->list_elem_size);
list->nb_elem++;
@@ -1759,16 +1759,13 @@ static int matroska_deliver_packet(MatroskaDemuxContext
*matroska,
memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
av_free(matroska->packets[0]);
if (matroska->num_packets > 1) {
- void *newpackets;
memmove(&matroska->packets[0], &matroska->packets[1],
(matroska->num_packets - 1) * sizeof(AVPacket *));
- newpackets = av_realloc(matroska->packets,
- (matroska->num_packets - 1) * sizeof(AVPacket *));
- if (newpackets)
- matroska->packets = newpackets;
- } else {
- av_freep(&matroska->packets);
- matroska->prev_pkt = NULL;
+ av_reallocp_array(&matroska->packets, matroska->num_packets - 1,
sizeof(AVPacket *));
+ if (!matroska->packets) {
+ matroska->num_packets = 0;
+ matroska->prev_pkt = NULL;
+ }
}
matroska->num_packets--;
return 0;
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 67d2350..438a206 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -297,8 +297,8 @@ static int mkv_add_seekhead_entry(mkv_seekhead *seekhead,
unsigned int elementid
if (seekhead->max_entries > 0 && seekhead->max_entries <=
seekhead->num_entries)
return -1;
- entries = av_realloc(entries, (seekhead->num_entries + 1) *
sizeof(mkv_seekhead_entry));
- if (entries == NULL)
+ av_reallocp(&entries, (seekhead->num_entries + 1) *
sizeof(mkv_seekhead_entry));
+ if (!entries)
return AVERROR(ENOMEM);
entries[seekhead->num_entries ].elementid = elementid;
@@ -378,9 +378,11 @@ static int mkv_add_cuepoint(mkv_cues *cues, int stream,
int64_t ts, int64_t clus
if (ts < 0)
return 0;
- entries = av_realloc(entries, (cues->num_entries + 1) *
sizeof(mkv_cuepoint));
- if (entries == NULL)
+ av_reallocp_array(&entries, cues->num_entries + 1, sizeof(mkv_cuepoint));
+ if (!entries) {
+ cues->num_entries = 0;
return AVERROR(ENOMEM);
+ }
entries[cues->num_entries ].pts = ts;
entries[cues->num_entries ].tracknum = stream + 1;
diff --git a/libavformat/mmst.c b/libavformat/mmst.c
index 4b96f5d..0628c41 100644
--- a/libavformat/mmst.c
+++ b/libavformat/mmst.c
@@ -334,13 +334,9 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext
*mmst)
packet_type = SC_PKT_ASF_HEADER;
// Store the asf header
if(!mms->header_parsed) {
- void *p = av_realloc(mms->asf_header,
- mms->asf_header_size +
mms->remaining_in_len);
- if (!p) {
- av_freep(&mms->asf_header);
+ av_reallocp(&mms->asf_header, mms->asf_header_size +
mms->remaining_in_len);
+ if (!mms->asf_header)
return AVERROR(ENOMEM);
- }
- mms->asf_header = p;
memcpy(mms->asf_header + mms->asf_header_size,
mms->read_in_ptr, mms->remaining_in_len);
mms->asf_header_size += mms->remaining_in_len;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0c938cd..7c925ff 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -877,7 +877,6 @@ static int mov_read_extradata(MOVContext *c, AVIOContext
*pb, MOVAtom atom)
{
AVStream *st;
uint64_t size;
- uint8_t *buf;
if (c->fc->nb_streams < 1) // will happen with jp2 files
return 0;
@@ -885,15 +884,14 @@ static int mov_read_extradata(MOVContext *c, AVIOContext
*pb, MOVAtom atom)
size= (uint64_t)st->codec->extradata_size + atom.size + 8 +
FF_INPUT_BUFFER_PADDING_SIZE;
if (size > INT_MAX || (uint64_t)atom.size > INT_MAX)
return AVERROR_INVALIDDATA;
- buf= av_realloc(st->codec->extradata, size);
- if (!buf)
+ st->codec->extradata = av_malloc(size);
+ if (!st->codec->extradata)
return AVERROR(ENOMEM);
- st->codec->extradata= buf;
- buf+= st->codec->extradata_size;
- st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE;
- AV_WB32( buf , atom.size + 8);
- AV_WL32( buf + 4, atom.type);
- avio_read(pb, buf + 8, atom.size);
+ st->codec->extradata += st->codec->extradata_size;
+ st->codec->extradata_size = size - FF_INPUT_BUFFER_PADDING_SIZE;
+ AV_WB32(st->codec->extradata, atom.size + 8);
+ AV_WL32(st->codec->extradata + 4, atom.type);
+ avio_read(pb, st->codec->extradata + 8, atom.size);
return 0;
}
@@ -1774,7 +1772,6 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
unsigned int stps_index = 0;
unsigned int i, j;
uint64_t stream_size = 0;
- AVIndexEntry *mem;
/* adjust first dts according to edit list */
if (sc->time_offset && mov->time_scale > 0) {
@@ -1808,10 +1805,9 @@ static void mov_build_index(MOVContext *mov, AVStream
*st)
return;
if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) -
st->nb_index_entries)
return;
- mem = av_realloc(st->index_entries, (st->nb_index_entries +
sc->sample_count) * sizeof(*st->index_entries));
- if (!mem)
+ av_reallocp_array(&st->index_entries, st->nb_index_entries +
sc->sample_count, sizeof(*st->index_entries));
+ if (!st->index_entries)
return;
- st->index_entries = mem;
st->index_entries_allocated_size = (st->nb_index_entries +
sc->sample_count) * sizeof(*st->index_entries);
for (i = 0; i < sc->chunk_count; i++) {
@@ -1906,10 +1902,9 @@ static void mov_build_index(MOVContext *mov, AVStream
*st)
av_dlog(mov->fc, "chunk count %d\n", total);
if (total >= UINT_MAX / sizeof(*st->index_entries) -
st->nb_index_entries)
return;
- mem = av_realloc(st->index_entries, (st->nb_index_entries + total) *
sizeof(*st->index_entries));
- if (!mem)
+ av_reallocp_array(&st->index_entries, st->nb_index_entries + total,
sizeof(*st->index_entries));
+ if (!st->index_entries)
return;
- st->index_entries = mem;
st->index_entries_allocated_size = (st->nb_index_entries + total) *
sizeof(*st->index_entries);
// populate index
@@ -2247,9 +2242,12 @@ static int mov_read_trex(MOVContext *c, AVIOContext *pb,
MOVAtom atom)
if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data))
return AVERROR_INVALIDDATA;
- trex = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data));
- if (!trex)
+ trex = c->trex_data;
+ av_reallocp_array(&trex, c->trex_count + 1, sizeof(*c->trex_data));
+ if (!trex) {
+ c->trex_count = 0;
return AVERROR(ENOMEM);
+ }
c->trex_data = trex;
trex = &c->trex_data[c->trex_count++];
avio_r8(pb); /* version */
@@ -2310,12 +2308,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext
*pb, MOVAtom atom)
}
if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
return AVERROR_INVALIDDATA;
- ctts_data = av_realloc(sc->ctts_data,
- (entries+sc->ctts_count)*sizeof(*sc->ctts_data));
- if (!ctts_data)
+ av_reallocp_array(&sc->ctts_data, entries + sc->ctts_count,
sizeof(*sc->ctts_data));
+ if (!sc->ctts_data) {
+ sc->ctts_count = 0;
return AVERROR(ENOMEM);
- sc->ctts_data = ctts_data;
-
+ }
if (flags & MOV_TRUN_DATA_OFFSET) data_offset =
avio_rb32(pb);
if (flags & MOV_TRUN_FIRST_SAMPLE_FLAGS) first_sample_flags =
avio_rb32(pb);
dts = sc->track_end - sc->time_offset;
diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c
index 05a43cf..9046afa 100644
--- a/libavformat/movenchint.c
+++ b/libavformat/movenchint.c
@@ -104,12 +104,10 @@ static void sample_queue_push(HintSampleQueue *queue,
uint8_t *data, int size,
if (size <= 14)
return;
if (!queue->samples || queue->len >= queue->size) {
- HintSample *samples;
queue->size += 10;
- samples = av_realloc(queue->samples, sizeof(HintSample)*queue->size);
- if (!samples)
- return;
- queue->samples = samples;
+ av_reallocp(&queue->samples, sizeof(HintSample) * queue->size);
+ if (!queue->samples)
+ return AVERROR(ENOMEM);
}
queue->samples[queue->len].data = data;
queue->samples[queue->len].size = size;
--
1.7.10.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel