Merge pull request #276 from Thealexbarney/msvc-fread-fix

Workaround MSVC fseek/fread bug
This commit is contained in:
Christopher Snowhill 2018-08-19 16:15:54 -07:00 committed by GitHub
commit 1294f515f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,6 +76,17 @@ static size_t read_stdio(STDIOSTREAMFILE *streamfile,uint8_t * dest, off_t offse
else
length_to_read = length;
#ifdef _MSC_VER
/* Workaround a bug that appears when compiling witn MSVC.
* This bug is dertiministic and seemingly appears randomly
* after seeking.
* It results in fread returning data from the wrong
* area of the file.
* HPS is one format that is almost always affected
* by this. */
fseek(streamfile->infile, ftell(streamfile->infile), SEEK_SET);
#endif
/* fill the buffer */
length_read = fread(streamfile->buffer,sizeof(uint8_t),streamfile->buffersize,streamfile->infile);
streamfile->validsize = length_read;