Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Windows: hack vs a weird bug in VC2015 fseek()
By a sheer coincidence one user have stumbled on what seems like a bug in MSVC standard library. The fseek fails to correctly position a stream at particular position, possibly depending on the current position too. The curious detail: no error is set, and ftell() reports a correct desired position after fseek, but next call to fread actually reads from a wrong place. This may or not be related to internal stream buffering by standard library. The workaround is to rewind the stream to the beginning first, and then seek to a wanted position. I confirmed that this problem does not happen in later versions of VC (tried VC2019), nor on Linux. Replicating this error in real game may be nearly impossible, so for the record, here's the confirmed failing case: start 0x000000 seek to 0xb19b00 read to 0xb1bb00 seek to 0xb1bb00 // no actual move read to 0xb1db00 seek to 0xb1ca3a // seeking back here read to 0xb69512 seek to 0xb69512 // no actual move read to 0xb6ba3a seek to 0xb6ba3a // no actual move read to 0xb6da3a seek to 0xb6ce45 // seeking back here --- fail location reading anything from here reads from (supposedly) further position. NOTE: in order to replicate this file must be few KBs bigger.
- Loading branch information