diff options
Diffstat (limited to 'lib/io/src/win32')
-rw-r--r-- | lib/io/src/win32/istream.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c index 918b868..94c8584 100644 --- a/lib/io/src/win32/istream.c +++ b/lib/io/src/win32/istream.c @@ -23,27 +23,25 @@ static int file_precache(istream_t *strm) DWORD diff, actual; HANDLE hnd; - if (strm->buffer_offset >= strm->buffer_used) { - strm->buffer_offset = 0; - strm->buffer_used = 0; - } else if (strm->buffer_offset > 0) { - memmove(strm->buffer, - strm->buffer + strm->buffer_offset, - strm->buffer_used - strm->buffer_offset); - - strm->buffer_used -= strm->buffer_offset; - strm->buffer_offset = 0; - } - if (strm->eof) return 0; + assert(strm->buffer >= file->buffer); + assert(strm->buffer <= (file->buffer + BUFSZ)); + assert(strm->buffer_used <= BUFSZ); + assert((size_t)(strm->buffer - file->buffer) <= + (BUFSZ - strm->buffer_used)); + + if (strm->buffer_used > 0) + memmove(file->buffer, strm->buffer, strm->buffer_used); + + strm->buffer = file->buffer; hnd = file->path == NULL ? GetStdHandle(STD_INPUT_HANDLE) : file->hnd; while (strm->buffer_used < sizeof(file->buffer)) { diff = sizeof(file->buffer) - strm->buffer_used; - if (!ReadFile(hnd, strm->buffer + strm->buffer_used, + if (!ReadFile(hnd, file->buffer + strm->buffer_used, diff, &actual, NULL)) { DWORD error = GetLastError(); |