[FFmpeg-cvslog] avcodec/movtextenc: Reset AVBPrint at the beginning, not end of encoding

Andreas Rheinhardt git at videolan.org
Thu Dec 2 09:08:17 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Nov 30 09:24:51 2021 +0100| [0b934f8f17c19be6b73cc5ecc9a23f7451bee5d0] | committer: Andreas Rheinhardt

avcodec/movtextenc: Reset AVBPrint at the beginning, not end of encoding

This avoids abusing a variable called length for the return value
and ensures that the AVBPrint is always reset before using it;
previously this has been forgotten in some error paths.

Reviewed-by: Philip Langdale <philipl at overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0b934f8f17c19be6b73cc5ecc9a23f7451bee5d0
---

 libavcodec/movtextenc.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c
index 0632463a63..46109e0a5e 100644
--- a/libavcodec/movtextenc.c
+++ b/libavcodec/movtextenc.c
@@ -646,6 +646,7 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
     s->text_pos = 0;
     s->count = 0;
     s->box_flags = 0;
+    av_bprint_clear(&s->buffer);
     for (i = 0; i < sub->num_rects; i++) {
         const char *ass = sub->rects[i]->ass;
 
@@ -669,27 +670,20 @@ static int mov_text_encode_frame(AVCodecContext *avctx, unsigned char *buf,
     AV_WB16(buf, s->byte_count);
     buf += 2;
 
-    if (!av_bprint_is_complete(&s->buffer)) {
-        length = AVERROR(ENOMEM);
-        goto exit;
-    }
+    if (!av_bprint_is_complete(&s->buffer))
+        return AVERROR(ENOMEM);
 
-    if (!s->buffer.len) {
-        length = 0;
-        goto exit;
-    }
+    if (!s->buffer.len)
+        return 0;
 
     if (s->buffer.len > bufsize - 3) {
         av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n");
-        length = AVERROR_BUFFER_TOO_SMALL;
-        goto exit;
+        return AVERROR_BUFFER_TOO_SMALL;
     }
 
     memcpy(buf, s->buffer.str, s->buffer.len);
     length = s->buffer.len + 2;
 
-exit:
-    av_bprint_clear(&s->buffer);
     return length;
 }
 



More information about the ffmpeg-cvslog mailing list