Fixes instant multiplayer crash on OS X Lion (10.7). libc++ had a bug where it set eofbit on reading the last character in a stringstream, we compare gcount with the expected length as a workaround to detect real eofs. Fixes #3109.

This was SVN commit r16714.
This commit is contained in:
historic_bruno 2015-06-04 05:11:47 +00:00
parent 6506bc20cb
commit f6f4f83784

View File

@ -81,8 +81,14 @@ void CStdDeserializer::Get(const char* name, u8* data, size_t len)
UNUSED2(name); UNUSED2(name);
#endif #endif
m_Stream.read((char*)data, (std::streamsize)len); m_Stream.read((char*)data, (std::streamsize)len);
if (!m_Stream.good()) // hit eof before len, or other errors if (!m_Stream.good())
{
// hit eof before len, or other errors
// Note: older libc++ versions incorrectly set eofbit on the last char; test gcount as a workaround
// see https://llvm.org/bugs/show_bug.cgi?id=9335
if (m_Stream.bad() || m_Stream.fail() || (m_Stream.eof() && m_Stream.gcount() != (std::streamsize)len))
throw PSERROR_Deserialize_ReadFailed(); throw PSERROR_Deserialize_ReadFailed();
}
} }
std::istream& CStdDeserializer::GetStream() std::istream& CStdDeserializer::GetStream()