[PATCH 2/2] memblockq: Limit rewinding so that it never results in a negative read index.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For completeness, maybe it would make sense to also limit
seeking so that the write index never gets negative...
---
 src/pulsecore/memblockq.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c
index c76ca84..b0cbc4d 100644
--- a/src/pulsecore/memblockq.c
+++ b/src/pulsecore/memblockq.c
@@ -646,7 +646,12 @@ void pa_memblockq_rewind(pa_memblockq *bq, size_t length) {
 
     /* This is kind of the inverse of pa_memblockq_drop() */
 
-    bq->read_index -= (int64_t) length;
+    if (bq->read_index >= (int64_t) length)
+        bq->read_index -= (int64_t) length;
+    else {
+        pa_log_debug("Limiting rewinding to %li bytes to avoid negative read index.", (long) bq->read_index);
+        bq->read_index = 0;
+    }
 
     read_index_changed(bq, old);
 }
-- 
1.7.5.3


--=-c1lh/DcIg7k+Y9O6OMo/--



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux