ZoneCodeGenerator: Fix throwing overflow exceptions too early due to wrong limit testing

This commit is contained in:
Jan 2019-11-15 14:52:10 +01:00
parent ec9be6e1fd
commit 51862d8596

View File

@ -113,7 +113,7 @@ void XBlockInputStream::LoadDataInBlock(void* dst, const size_t size)
throw OutOfBlockBoundsException(block); throw OutOfBlockBoundsException(block);
} }
if(reinterpret_cast<uint8_t*>(dst) + size >= block->m_buffer + block->m_buffer_size) if(reinterpret_cast<uint8_t*>(dst) + size > block->m_buffer + block->m_buffer_size)
{ {
throw BlockOverflowException(block); throw BlockOverflowException(block);
} }
@ -158,14 +158,14 @@ void XBlockInputStream::LoadNullTerminated(void* dst)
size_t offset = reinterpret_cast<uint8_t*>(dst) - block->m_buffer; size_t offset = reinterpret_cast<uint8_t*>(dst) - block->m_buffer;
do do
{ {
m_stream->Load(&byte, 1); if (offset >= block->m_buffer_size)
block->m_buffer[offset++] = byte;
if(offset >= block->m_buffer_size)
{ {
throw BlockOverflowException(block); throw BlockOverflowException(block);
} }
m_stream->Load(&byte, 1);
block->m_buffer[offset++] = byte;
} while(byte != 0); } while(byte != 0);
m_block_offsets[block->m_index] = offset; m_block_offsets[block->m_index] = offset;
@ -177,7 +177,7 @@ void** XBlockInputStream::InsertPointer()
Align(sizeof(void*)); Align(sizeof(void*));
if(m_block_offsets[m_insert_block->m_index] + sizeof(void*) >= m_insert_block->m_buffer_size) if(m_block_offsets[m_insert_block->m_index] + sizeof(void*) > m_insert_block->m_buffer_size)
{ {
throw BlockOverflowException(m_insert_block); throw BlockOverflowException(m_insert_block);
} }