[FFmpeg-cvslog] lavu/fifo: fix a corner case in av_fifo_grow2()

Anton Khirnov git at videolan.org
Tue Feb 15 11:19:35 EET 2022


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Feb  8 19:13:45 2022 +0100| [e9acff8a013bdd6d459116ceb35f8a53b60ff521] | committer: Anton Khirnov

lavu/fifo: fix a corner case in av_fifo_grow2()

When the fifo is grown by exactly the current write offset, it would end
up with offset_w = nb_elems. If av_fifo_write_from_cb() is called in
such a state, the user callback would get callled with *nb_elems=0,
which will then cause the write to return without writing anything.

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

 libavutil/fifo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 02e0ec3f0d..09c984143f 100644
--- a/libavutil/fifo.c
+++ b/libavutil/fifo.c
@@ -115,7 +115,7 @@ int av_fifo_grow2(AVFifo *f, size_t inc)
                     (f->offset_w - copy) * f->elem_size);
             f->offset_w -= copy;
         } else
-            f->offset_w = f->nb_elems + copy;
+            f->offset_w = copy == inc ? 0 : f->nb_elems + copy;
     }
 
     f->nb_elems += inc;



More information about the ffmpeg-cvslog mailing list