diff mbox series

[FFmpeg-devel,1/2] lavu/fifo: fix a corner case in av_fifo_grow2()

Message ID 20220208182614.25504-1-anton@khirnov.net
State Accepted
Commit e9acff8a013bdd6d459116ceb35f8a53b60ff521
Headers show
Series [FFmpeg-devel,1/2] lavu/fifo: fix a corner case in av_fifo_grow2() | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Anton Khirnov Feb. 8, 2022, 6:26 p.m. UTC
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.
---
 libavutil/fifo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavutil/fifo.c b/libavutil/fifo.c
index 0af0154945..2af8842cc5 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;