[MPlayer-dev-eng] [PATCH] Fix stream_write_buffer

Thierry Foucu tfoucu at gmail.com
Mon May 10 18:37:55 CEST 2010


Hi

Fix stream_write_buffer to make sure all requested bytes are written (or
until an error occurs) since none of the calling sites are checking the
return value to see if ALL bytes got written.

Index: stream/stream.c
=================================================================== ---
stream/stream.c (revision 31151) +++ stream/stream.c (working copy) @@
-293,13 +293,16 @@ } int stream_write_buffer(stream_t *s, unsigned char
*buf, int len) { - int rd; - if(!s->write_buffer) + int rd = 0; +
if(!s->write_buffer || (len < 0)) return -1; - rd = s->write_buffer(s, buf,
len); - if(rd < 0) - return -1; - s->pos += rd; + while (rd < len) { + int
ret = s->write_buffer(s, buf+rd, len-rd); + if (ret < 0) + return -1; + rd
+= ret; + s->pos += ret; + } return rd; }
-------------- next part --------------
Index: stream/stream.c
===================================================================
--- stream/stream.c	(revision 31151)
+++ stream/stream.c	(working copy)
@@ -293,13 +293,16 @@
 }
 
 int stream_write_buffer(stream_t *s, unsigned char *buf, int len) {
-  int rd;
-  if(!s->write_buffer)
+  int rd = 0;
+  if(!s->write_buffer || (len < 0))
     return -1;
-  rd = s->write_buffer(s, buf, len);
-  if(rd < 0)
-    return -1;
-  s->pos += rd;
+  while (rd < len) {
+    int ret = s->write_buffer(s, buf+rd, len-rd);
+    if (ret < 0)
+      return -1;
+    rd += ret;
+    s->pos += ret;
+  }
   return rd;
 }
 


More information about the MPlayer-dev-eng mailing list