Make sure read buffers get reinitialized before refilling (thanks, Michael!).
authorRyan C. Gordon <icculus@icculus.org>
Thu, 11 Sep 2014 00:07:23 -0400
changeset 1355 52a7487e505c
parent 1354 3e80839670da
child 1356 8de68968fcd0
Make sure read buffers get reinitialized before refilling (thanks, Michael!).
docs/CREDITS.txt
src/physfs.c
--- a/docs/CREDITS.txt	Tue Aug 19 10:55:56 2014 -0400
+++ b/docs/CREDITS.txt	Thu Sep 11 00:07:23 2014 -0400
@@ -139,6 +139,9 @@
 Bug fixes:
     Andreas Karlsson
 
+Bug fixes:
+    Michael Bacon
+
 pkg-config support:
     Jonas Kulla
 
--- a/src/physfs.c	Tue Aug 19 10:55:56 2014 -0400
+++ b/src/physfs.c	Thu Sep 11 00:07:23 2014 -0400
@@ -2556,20 +2556,21 @@
         memcpy(buffer, fh->buffer + fh->bufpos, (size_t) len);
         fh->bufpos += (PHYSFS_uint32) len;
         return (PHYSFS_sint64) len;
-    } /* else if */
-
-    if (buffered > 0) /* partially in the buffer... */
+    } /* if */
+
+    else if (buffered > 0) /* partially in the buffer... */
     {
         memcpy(buffer, fh->buffer + fh->bufpos, (size_t) buffered);
         buffer = ((PHYSFS_uint8 *) buffer) + buffered;
         len -= buffered;
         retval = buffered;
-        fh->buffill = fh->bufpos = 0;
     } /* if */
 
     /* if you got here, the buffer is drained and we still need bytes. */
     assert(len > 0);
 
+    fh->buffill = fh->bufpos = 0;
+
     io = fh->io;
     if (len >= fh->bufsize)  /* need more than the buffer takes. */
     {