On 02/08/13 18:56, Alexandra Khirnova wrote:
> ---
>  libavformat/mpegts.c |    7 ++++---
>  libavformat/mxfdec.c |   24 ++++++++++++++----------
>  libavformat/oggdec.c |   16 +++++++---------
>  libavformat/utils.c  |   10 +++++-----
>  4 files changed, 30 insertions(+), 27 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 1540a8d..5fb879f 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -198,10 +198,11 @@ static void clear_programs(MpegTSContext *ts)
>  static void add_pat_entry(MpegTSContext *ts, unsigned int programid)
>  {
>      struct Program *p;
> -    void *tmp = av_realloc(ts->prg, (ts->nb_prg+1)*sizeof(struct Program));
> -    if(!tmp)
> +    av_reallocp_array(&ts->prg, ts->nb_prg + 1, sizeof(struct Program));

Better if you use the return value.

> +    if (!ts->prg) {
> +        ts->nb_prg = 0;
>          return;
> -    ts->prg = tmp;
> +    }
>      p = &ts->prg[ts->nb_prg];
>      p->id = programid;
>      p->nb_pids = 0;
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index d2039f6..7c0f657 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -410,18 +410,20 @@ static int mxf_read_primer_pack(void *arg, AVIOContext 
> *pb, int tag, int size, U
>  static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int 
> size, UID uid, int64_t klv_offset)
>  {
>      MXFContext *mxf = arg;
> -    MXFPartition *partition, *tmp_part;
> +    MXFPartition *partition;
>      UID op;
>      uint64_t footer_partition;
>      uint32_t nb_essence_containers;
> +    int err;
>  
>      if (mxf->partitions_count+1 >= UINT_MAX / sizeof(*mxf->partitions))
>          return AVERROR(ENOMEM);
>  
> -    tmp_part = av_realloc(mxf->partitions, (mxf->partitions_count + 1) * 
> sizeof(*mxf->partitions));
> -    if (!tmp_part)
> -        return AVERROR(ENOMEM);
> -    mxf->partitions = tmp_part;
> +    if ((err = av_reallocp_array(&mxf->partitions, mxf->partitions_count + 1,
> +                                 sizeof(*mxf->partitions))) < 0) {
> +        mxf->partitions_count = 0;
> +        return err;
> +    }
>  
>      if (mxf->parsing_backward) {
>          /* insert the new partition pack in the middle
> @@ -546,13 +548,15 @@ static int mxf_read_partition_pack(void *arg, 
> AVIOContext *pb, int tag, int size
>  
>  static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
>  {
> -    MXFMetadataSet **tmp;
> +    int err;
> +
>      if (mxf->metadata_sets_count+1 >= UINT_MAX / sizeof(*mxf->metadata_sets))
>          return AVERROR(ENOMEM);
> -    tmp = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * 
> sizeof(*mxf->metadata_sets));
> -    if (!tmp)
> -        return AVERROR(ENOMEM);
> -    mxf->metadata_sets = tmp;
> +    if ((err = av_reallocp_array(&mxf->metadata_sets, 
> mxf->metadata_sets_count + 1,
> +                                 sizeof(*mxf->metadata_sets))) < 0) {
> +        mxf->metadata_sets_count = 0;
> +        return err;
> +    }
>      mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set;
>      mxf->metadata_sets_count++;
>      return 0;
> diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
> index 6514c5b..48d146e 100644
> --- a/libavformat/oggdec.c
> +++ b/libavformat/oggdec.c
> @@ -84,7 +84,7 @@ static int ogg_restore(AVFormatContext *s, int discard)
>      struct ogg *ogg = s->priv_data;
>      AVIOContext *bc = s->pb;
>      struct ogg_state *ost = ogg->state;
> -    int i;
> +    int i, err;
>  
>      if (!ost)
>          return 0;
> @@ -100,16 +100,14 @@ static int ogg_restore(AVFormatContext *s, int discard)
>          avio_seek(bc, ost->pos, SEEK_SET);
>          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;
> -        }
>      }
>  
>      av_free(ost);
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 80b1ce2..4c407db 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2565,14 +2565,14 @@ AVStream *avformat_new_stream(AVFormatContext *s, 
> AVCodec *c)
>  {
>      AVStream *st;
>      int i;
> -    AVStream **streams;
>  
> -    if (s->nb_streams >= INT_MAX/sizeof(*streams))
> +    if (s->nb_streams >= INT_MAX/sizeof(s->streams))
>          return NULL;

reallocp array should check that one as well.

> -    streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));
> -    if (!streams)
> +    av_reallocp_array(&s->streams, s->nb_streams + 1, sizeof(s->streams));
> +    if (!s->streams) {

In such cases use the return value to check and not the variable.

lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to