fixed a MemoryStream issue that broke JPEG unserialization

metadata
Wenzel Jakob 2011-06-17 14:39:39 +02:00
parent 782a7a3c19
commit 483d6aa942
1 changed files with 7 additions and 2 deletions

View File

@ -86,8 +86,13 @@ void MemoryStream::truncate(size_t size) {
} }
void MemoryStream::read(void *ptr, size_t size) { void MemoryStream::read(void *ptr, size_t size) {
if (m_pos + size > m_size) if (m_pos + size > m_size) {
Log(EError, "Reading over the end of a memory stream!"); size_t sizeRead = m_size - m_pos;
memcpy(ptr, m_data + m_pos, sizeRead);
m_pos += sizeRead;
throw EOFException(formatString("Reading over the end of a memory stream (amount requested=" SIZE_T_FMT
", amount read=" SIZE_T_FMT ")!", size, sizeRead), sizeRead);
}
memcpy(ptr, m_data + m_pos, size); memcpy(ptr, m_data + m_pos, size);
m_pos += size; m_pos += size;
} }