[FFmpeg-cvslog] avcodec/cbs: Remove redundant checks for CodedBitstreamContext.codec

Andreas Rheinhardt git at videolan.org
Sat Mar 13 00:43:16 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Tue Mar  9 20:16:04 2021 +0100| [85685297c28958f3a8fa50a50ed3a6171e7f34c2] | committer: Andreas Rheinhardt

avcodec/cbs: Remove redundant checks for CodedBitstreamContext.codec

Setting this field happens immediately after the allocation in
ff_cbs_init(), so the whole CBS code may presume that any
CodedBitstreamContext has this set. Lots of code already presumed this,
yet ff_cbs_close() did it inconsistently: It checked before checking
whether the CodedBitstreamType has a close function; yet it simply
unconditionally read ctx->codec->priv_class. Coverity complained about
this in issue #1473564, which this commit fixes.

Reviewed-by: Mark Thompson <sw at jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

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

 libavcodec/cbs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index ecf22b3fdb..c7f69845fb 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -94,7 +94,7 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
         return AVERROR(ENOMEM);
 
     ctx->log_ctx = log_ctx;
-    ctx->codec   = type;
+    ctx->codec   = type; /* Must be before any error */
 
     if (type->priv_data_size) {
         ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
@@ -119,7 +119,7 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
 
 void ff_cbs_flush(CodedBitstreamContext *ctx)
 {
-    if (ctx->codec && ctx->codec->flush)
+    if (ctx->codec->flush)
         ctx->codec->flush(ctx);
 }
 
@@ -130,7 +130,7 @@ void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
     if (!ctx)
         return;
 
-    if (ctx->codec && ctx->codec->close)
+    if (ctx->codec->close)
         ctx->codec->close(ctx);
 
     av_freep(&ctx->write_buffer);



More information about the ffmpeg-cvslog mailing list