[FFmpeg-devel] [PATCH 10/10] avformat/nutenc: Don't allocate array with zero entries

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon May 4 21:22:50 EEST 2020


Allocating an array with zero entries is both unnecessary as well as
potentially troublesome because the behaviour in this case is not really
well defined.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/nutenc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 6df7dfe210..5071278835 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -711,11 +711,15 @@ static int nut_write_header(AVFormatContext *s)
     }
 
     nut->stream   = av_calloc(s->nb_streams,  sizeof(*nut->stream ));
-    nut->chapter  = av_calloc(s->nb_chapters, sizeof(*nut->chapter));
     nut->time_base= av_calloc(s->nb_streams +
                               s->nb_chapters, sizeof(*nut->time_base));
-    if (!nut->stream || !nut->chapter || !nut->time_base)
+    if (!nut->stream || !nut->time_base)
         return AVERROR(ENOMEM);
+    if (s->nb_chapters) {
+        nut->chapter = av_calloc(s->nb_chapters, sizeof(*nut->chapter));
+        if (!nut->chapter)
+            return AVERROR(ENOMEM);
+    }
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-- 
2.20.1



More information about the ffmpeg-devel mailing list