I'm working with some (legacy) code that opens a file (binary) and reads a bunch of integers, floats, doubles and characters from it. Some relevant code:
std::ifstream infoFile(path.c_str(), std::ios_base::binary);
while (infoFile.good()){
infoFile.peek();
if (infoFile.eof())
break;
// Read all kinds of things
}
The above is being called quite a few times (2*86 times in my tests) on the same file, possibly parallel. This is a small piece of code in a large codebase, it's very difficult to extract a standalone piece of code.
After an unpredictable number of file reads, the position of the stream changes unpredictably. I've printed tellg
before and after the call to peek
in the above code and on these rare occasions it changed! I tried mutex
-protecting access to this file, made no difference. I'm completely stumped as to how this would be possible, so if anyone has an idea of how this is actually possible that would be a great help.