[FFmpeg-cvslog] avcodec/mpegvideo_enc: Don't overallocate arrays
Andreas Rheinhardt
git at videolan.org
Tue Oct 10 01:32:00 EEST 2023
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Oct 5 01:01:35 2023 +0200| [3937a21f219165425146b06fbf9b908bc1ae6d27] | committer: Andreas Rheinhardt
avcodec/mpegvideo_enc: Don't overallocate arrays
Only entries 0..max_b_frames are ever used.
Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3937a21f219165425146b06fbf9b908bc1ae6d27
---
libavcodec/mpegvideo_enc.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index b32197b1b4..d30cbab29d 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -819,8 +819,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16, 32) ||
!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) ||
!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16, 32) ||
- !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_PICTURE_COUNT) ||
- !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_PICTURE_COUNT) ||
+ !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_B_FRAMES + 1) ||
+ !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_B_FRAMES + 1) ||
!(s->new_picture = av_frame_alloc()))
return AVERROR(ENOMEM);
@@ -1232,7 +1232,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg)
}
/* shift buffer entries */
- for (i = flush_offset; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++)
+ for (int i = flush_offset; i <= MAX_B_FRAMES; i++)
s->input_picture[i - flush_offset] = s->input_picture[i];
s->input_picture[encoding_delay] = pic;
@@ -1451,9 +1451,9 @@ static int select_input_picture(MpegEncContext *s)
{
int i, ret;
- for (i = 1; i < MAX_PICTURE_COUNT; i++)
+ for (int i = 1; i <= MAX_B_FRAMES; i++)
s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];
- s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL;
+ s->reordered_input_picture[MAX_B_FRAMES] = NULL;
/* set next picture type & ordering */
if (!s->reordered_input_picture[0] && s->input_picture[0]) {
More information about the ffmpeg-cvslog
mailing list