1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Merge pull request #13938 from janisozaur/nullptr_check

Add nullptr check in get_loaded_object_entry
This commit is contained in:
ζeh Matt
2021-01-27 08:14:04 +02:00
committed by GitHub
2 changed files with 7 additions and 2 deletions

View File

@@ -138,8 +138,13 @@ const rct_object_entry* get_loaded_object_entry(size_t index)
ObjectType objectType; ObjectType objectType;
ObjectEntryIndex entryIndex; ObjectEntryIndex entryIndex;
get_type_entry_index(index, &objectType, &entryIndex); get_type_entry_index(index, &objectType, &entryIndex);
auto obj = object_entry_get_object(objectType, entryIndex);
if (obj == nullptr)
{
return nullptr;
}
return object_entry_get_object(objectType, entryIndex)->GetObjectEntry(); return obj->GetObjectEntry();
} }
void* get_loaded_object_chunk(size_t index) void* get_loaded_object_chunk(size_t index)

View File

@@ -168,7 +168,7 @@ void S6Exporter::Export()
const rct_object_entry* entry = get_loaded_object_entry(i); const rct_object_entry* entry = get_loaded_object_entry(i);
void* entryData = get_loaded_object_chunk(i); void* entryData = get_loaded_object_chunk(i);
// RCT2 uses (void *)-1 to mark NULL. Make sure it's written in a vanilla-compatible way. // RCT2 uses (void *)-1 to mark NULL. Make sure it's written in a vanilla-compatible way.
if (entryData == nullptr || entryData == reinterpret_cast<void*>(-1)) if (entry == nullptr || entryData == nullptr || entryData == reinterpret_cast<void*>(-1))
{ {
std::memset(&_s6.objects[i], 0xFF, sizeof(rct_object_entry)); std::memset(&_s6.objects[i], 0xFF, sizeof(rct_object_entry));
} }