On Tue, Sep 03, 2013 at 05:10:39PM +0200, Alexandra Khirnova wrote:
> --- a/libavformat/asfenc.c
> +++ b/libavformat/asfenc.c
> @@ -784,14 +784,18 @@ static int asf_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {
> + int err;
> start_sec = (int)(duration / INT64_C(10000000));
> if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {
> 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(*asf->index_ptr))) <
> 0) {
> + asf->nb_index_memory_alloc = 0;
> + return err;
> + }
> }
> // store
> asf->index_ptr[i].packet_number = (uint32_t)packet_st;
The err variable could be declared with smaller scope.
> --- a/libavformat/gxfenc.c
> +++ b/libavformat/gxfenc.c
> @@ -872,12 +874,14 @@ static int gxf_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> gxf_write_padding(pb, padding);
>
> if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
> + int err;
> if (!(gxf->flt_entries_nb % 500)) {
> - gxf->flt_entries = av_realloc(gxf->flt_entries,
> -
> (gxf->flt_entries_nb+500)*sizeof(*gxf->flt_entries));
> - if (!gxf->flt_entries) {
> + if ((err = av_reallocp_array(&gxf->flt_entries,
> + gxf->flt_entries_nb + 500,
> + sizeof(*gxf->flt_entries))) < 0) {
> + gxf->flt_entries_nb = 0;
> av_log(s, AV_LOG_ERROR, "could not reallocate flt
> entries\n");
> - return -1;
> + return err;
> }
> }
same
> --- a/libavformat/mov.c
> +++ b/libavformat/mov.c
> @@ -2307,12 +2310,16 @@ static int mov_read_chap(MOVContext *c, AVIOContext
> *pb, MOVAtom atom)
> static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
> {
> MOVTrackExt *trex;
> + int err;
>
> 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)
> - return AVERROR(ENOMEM);
> + trex = c->trex_data;
> + if ((err = av_reallocp_array(&trex, c->trex_count + 1,
> + sizeof(*c->trex_data))) < 0) {
> + c->trex_count = 0;
> + return err;
> + }
> c->trex_data = trex;
> trex = &c->trex_data[c->trex_count++];
> avio_r8(pb); /* version */
I think you shouldn't keep the trex variable indirection here, should you?
> --- a/libavformat/oggdec.c
> +++ b/libavformat/oggdec.c
> @@ -100,16 +100,14 @@ static int ogg_restore(AVFormatContext *s, int discard)
> ogg->curidx = ost->curidx;
> ogg->nstreams = ost->nstreams;
> - ogg->streams = av_realloc(ogg->streams,
> - ogg->nstreams * sizeof(*ogg->streams));
> -
> - if (ogg->streams) {
> + if ((err = av_reallocp_array(&ogg->streams, ogg->nstreams,
> + sizeof(*ogg->streams))) < 0) {
> + ogg->nstreams = 0;
> + av_free(ost);
> + return err;
> + } else
> memcpy(ogg->streams, ost->streams,
> ost->nstreams * sizeof(*ogg->streams));
> - } else {
> - av_free(old_streams);
> - ogg->nstreams = 0;
> - }
> }
Why do you free ost?
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2684,10 +2680,10 @@ void ff_program_add_stream_index(AVFormatContext *ac,
> int progid, unsigned int i
> if(program->stream_index[j] == idx)
> return;
>
> - tmp = av_realloc(program->stream_index, sizeof(unsigned
> int)*(program->nb_stream_indexes+1));
> - if(!tmp)
> + if (av_reallocp_array(&program->stream_index,
> + program->nb_stream_indexes + 1,
> + sizeof(*program->stream_index)) < 0)
> return;
> - program->stream_index = tmp;
> program->stream_index[program->nb_stream_indexes++] = idx;
> return;
> }
Doesn't this need setting program->nb_stream_indexes to 0?
Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel