On Thu, Nov 28, 2013 at 06:08:07PM +0100, Alexandra Khirnova wrote:
> --- a/libavcodec/bitstream.c
> +++ b/libavcodec/bitstream.c
> @@ -106,12 +106,16 @@ static int alloc_table(VLC *vlc, int size, int 
> use_static)
>      vlc->table_size += size;
>      if (vlc->table_size > vlc->table_allocated) {
> +        int err;
>          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) {
> +            vlc->table_allocated = 0;
> +            return err;
> +        }
>      }

It's not clear to me what the advantage of av_reallocp is here...

> --- a/libavcodec/eatgv.c
> +++ b/libavcodec/eatgv.c
> @@ -178,7 +178,9 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame,
>  
>      if (num_blocks_packed > s->num_blocks_packed) {
> -        s->block_codebook = av_realloc(s->block_codebook, 
> num_blocks_packed*16);
> +        int err;
> +        if ((err = av_reallocp(&s->block_codebook, num_blocks_packed * 16)) 
> < 0)
> +            return err;
>          s->num_blocks_packed = num_blocks_packed;
>      }

Similar, this seems like it could be done as a simple malloc check as well.

> --- a/libavcodec/flashsv.c
> +++ b/libavcodec/flashsv.c
> @@ -296,13 +296,11 @@ static int flashsv_decode_frame(AVCodecContext *avctx, 
> void *data,
>      /* the block size could change between frames, make sure the buffer
>       * is large enough, if not, get a larger one */
>      if (s->block_size < s->block_width * s->block_height) {
> -        int tmpblock_size = 3 * s->block_width * s->block_height;
> +        int tmpblock_size = 3 * s->block_width * s->block_height, err;
>  
> -        s->tmpblock = av_realloc(s->tmpblock, tmpblock_size);
> -        if (!s->tmpblock) {
> -            av_log(avctx, AV_LOG_ERROR,
> -                   "Cannot allocate decompression buffer.\n");
> -            return AVERROR(ENOMEM);
> +        if ((err = av_reallocp(&s->tmpblock, tmpblock_size)) < 0) {
> +            av_log(avctx, AV_LOG_ERROR, "Cannot allocate decompression 
> buffer.\n");
> +            return err;
>          }

same

Also, please don't make unrelated cosmetic changes to the av_log call.

> @@ -311,12 +309,9 @@ static int flashsv_decode_frame(AVCodecContext *avctx, 
> void *data,
> -            s->deflate_block = av_realloc(s->deflate_block,
> -                                          s->deflate_block_size);
> -            if (!s->deflate_block) {
> -                av_log(avctx, AV_LOG_ERROR,
> -                       "Cannot allocate deflate buffer.\n");
> -                return AVERROR(ENOMEM);
> +            if ((err = av_reallocp(&s->deflate_block, 
> s->deflate_block_size)) < 0) {
> +                av_log(avctx, AV_LOG_ERROR, "Cannot allocate deflate 
> buffer.\n");
> +                return err;
>              }

same

> @@ -340,11 +335,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;
>      }

same

> --- a/libavcodec/libtheoraenc.c
> +++ b/libavcodec/libtheoraenc.c
> @@ -58,8 +58,8 @@ static int concatenate_packet(unsigned int* offset,
>  {
>      const char* message = NULL;
> -    uint8_t* newdata    = NULL;
>      int newsize = avc_context->extradata_size + 2 + packet->bytes;
> +    int err = AVERROR_INVALIDDATA;
>  
> @@ -68,16 +68,16 @@ 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)
> +        if (av_reallocp(&avc_context->extradata, newsize) < 0) {
> +            avc_context->extradata_size = 0;
>              message = "av_realloc failed";
> +        }
>      }
>      if (message) {
>          av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", 
> message);
> -        return -1;
> +        return err;
>      }

You should propagate the return value from av_reallocp() here.

I'm not sure if AVERROR_INVALIDDATA is the appropriate default
return value here.

> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -467,11 +467,13 @@ static int queue_frames(AVCodecContext *avctx, AVPacket 
> *pkt_out,
>          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) {
> +                stats->sz = 0;
>                  av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
> -                return AVERROR(ENOMEM);
> +                return err;
>              }

Again, not sure what we gain from av_reallocp() here.


LGTM otherwise.  Did you verify this does not add any new warnings?

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

Reply via email to