---
libavformat/asfenc.c | 10 ++++++----
libavformat/gxfenc.c | 14 +++++++------
libavformat/matroskaenc.c | 12 ++++++++----
libavformat/mov.c | 48 +++++++++++++++++++++++----------------------
4 files changed, 47 insertions(+), 37 deletions(-)
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index a523b3a..d2922aa 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -764,7 +764,7 @@ static int asf_write_packet(AVFormatContext *s, AVPacket
*pkt)
int64_t duration;
AVCodecContext *codec;
int64_t packet_st, pts;
- int start_sec, i;
+ int start_sec, i, err;
int flags = pkt->flags;
codec = s->streams[pkt->stream_index]->codec;
@@ -789,9 +789,11 @@ 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 ((err = av_reallocp_array(&asf->index_ptr,
asf->nb_index_memory_alloc,
+ sizeof(ASFIndex))) < 0) {
+ asf->nb_index_memory_alloc = 0;
+ return err;
+ }
}
// store
asf->index_ptr[i].packet_number = (uint32_t)packet_st;
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/matroskaenc.c b/libavformat/matroskaenc.c
index 67d2350..c6eb07d 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -297,9 +297,11 @@ 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_array(&entries, seekhead->num_entries + 1,
sizeof(mkv_seekhead_entry));
+ if (!entries) {
+ seekhead->num_entries = 0;
return AVERROR(ENOMEM);
+ }
entries[seekhead->num_entries ].elementid = elementid;
entries[seekhead->num_entries++].segmentpos = filepos -
seekhead->segment_offset;
@@ -378,9 +380,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/mov.c b/libavformat/mov.c
index 0c938cd..80fac03 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,15 @@ 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)
+ av_freep(&st->codec->extradata);
+ 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 +1773,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 +1806,11 @@ 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) {
+ st->nb_index_entries = 0;
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 +1905,11 @@ 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) {
+ st->nb_index_entries = 0;
return;
- st->index_entries = mem;
+ }
st->index_entries_allocated_size = (st->nb_index_entries + total) *
sizeof(*st->index_entries);
// populate index
@@ -2247,9 +2247,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 +2313,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;
--
1.7.10.4
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel