Skip to content

Commit

Permalink
Make sure read buffers get reinitialized before refilling (thanks, Mi…
Browse files Browse the repository at this point in the history
…chael!).
  • Loading branch information
icculus committed Sep 11, 2014
1 parent c9f4034 commit f6a62ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/CREDITS.txt
Expand Up @@ -139,6 +139,9 @@ Bug fixes:
Bug fixes:
Andreas Karlsson

Bug fixes:
Michael Bacon

pkg-config support:
Jonas Kulla

Expand Down
7 changes: 4 additions & 3 deletions src/physfs.c
Expand Up @@ -2556,20 +2556,21 @@ static PHYSFS_sint64 doBufferedRead(FileHandle *fh, void *buffer,
memcpy(buffer, fh->buffer + fh->bufpos, (size_t) len);
fh->bufpos += (PHYSFS_uint32) len;
return (PHYSFS_sint64) len;
} /* else if */
} /* if */

if (buffered > 0) /* partially in the buffer... */
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. */
{
Expand Down

0 comments on commit f6a62ec

Please sign in to comment.