[vlc-devel] commit: decomp: fix reading after peeking ( Rémi Denis-Courmont )

git version control git at videolan.org
Tue Jan 13 21:59:10 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Tue Jan 13 22:56:04 2009 +0200| [7c321e8a48d3313533b92096e5fa81646e19907e] | committer: Rémi Denis-Courmont 

decomp: fix reading after peeking

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7c321e8a48d3313533b92096e5fa81646e19907e
---

 modules/stream_filter/decomp.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/modules/stream_filter/decomp.c b/modules/stream_filter/decomp.c
index 2466b47..f89d16d 100644
--- a/modules/stream_filter/decomp.c
+++ b/modules/stream_filter/decomp.c
@@ -153,26 +153,31 @@ static int Read (stream_t *stream, void *buf, unsigned int buflen)
 {
     stream_sys_t *p_sys = stream->p_sys;
     block_t *peeked;
-    size_t bonus = 0;
     ssize_t length;
 
     if ((peeked = p_sys->peeked) != NULL)
-    {
-        bonus = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen;
-        memcpy (buf, peeked->p_buffer, bonus);
-        peeked->p_buffer += bonus;
-        peeked->i_buffer -= bonus;
+    {   /* dequeue peeked data */
+        length = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen;
+        memcpy (buf, peeked->p_buffer, length);
+        buf = ((char *)buf) + length;
+        buflen -= length;
+        peeked->p_buffer += length;
+        peeked->i_buffer -= length;
         if (peeked->i_buffer == 0)
         {
             block_Release (peeked);
             p_sys->peeked = NULL;
         }
+        p_sys->offset += length;
+
+        if (buflen > 0)
+            length += Read (stream, ((char *)buf) + length, buflen - length);
+        return length;
     }
 
     length = net_Read (stream, p_sys->read_fd, NULL, buf, buflen, false);
     if (length < 0)
         return 0;
-    length += bonus;
     p_sys->offset += length;
     return length;
 }




More information about the vlc-devel mailing list