mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
ZoneCodeGenerator: Fix fastfile offsets being wrong by 1 due to not respecting that all offsets are moved by 1
This commit is contained in:
parent
51862d8596
commit
cd93106c19
@ -191,8 +191,12 @@ void** XBlockInputStream::InsertPointer()
|
||||
|
||||
void* XBlockInputStream::ConvertOffsetToPointer(const void* offset)
|
||||
{
|
||||
const block_t blockNum = reinterpret_cast<uintptr_t>(offset) >> (sizeof(offset) * 8 - m_block_bit_count);
|
||||
const size_t blockOffset = reinterpret_cast<uintptr_t>(offset) & (UINTPTR_MAX >> m_block_bit_count);
|
||||
// -1 because otherwise Block 0 Offset 0 would be just 0 which is already used to signalize a nullptr.
|
||||
// So all offsets are moved by 1.
|
||||
auto offsetInt = reinterpret_cast<uintptr_t>(offset) - 1;
|
||||
|
||||
const block_t blockNum = offsetInt >> (sizeof(offsetInt) * 8 - m_block_bit_count);
|
||||
const size_t blockOffset = offsetInt & (UINTPTR_MAX >> m_block_bit_count);
|
||||
|
||||
if(blockNum < 0 || blockNum >= static_cast<block_t>(m_blocks.size()))
|
||||
{
|
||||
@ -211,8 +215,11 @@ void* XBlockInputStream::ConvertOffsetToPointer(const void* offset)
|
||||
|
||||
void* XBlockInputStream::ConvertOffsetToAlias(const void* offset)
|
||||
{
|
||||
const block_t blockNum = reinterpret_cast<uintptr_t>(offset) >> (sizeof(offset) * 8 - m_block_bit_count);
|
||||
const size_t blockOffset = reinterpret_cast<uintptr_t>(offset) & (UINTPTR_MAX >> m_block_bit_count);
|
||||
// For details see ConvertOffsetToPointer
|
||||
auto offsetInt = reinterpret_cast<uintptr_t>(offset) - 1;
|
||||
|
||||
const block_t blockNum = offsetInt >> (sizeof(offsetInt) * 8 - m_block_bit_count);
|
||||
const size_t blockOffset = offsetInt & (UINTPTR_MAX >> m_block_bit_count);
|
||||
|
||||
if(blockNum < 0 || blockNum >= static_cast<block_t>(m_blocks.size()))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user