[Menus]: Fix crashes while parsing (#607)

This commit is contained in:
Edo 2022-11-28 18:06:42 +00:00 committed by GitHub
parent 95a220d162
commit a447a2945a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 7 deletions

View File

@ -12,7 +12,7 @@ namespace Assets
if (menus.empty()) return;
// Allocate new menu list
Game::MenuList* newList = allocator->allocate<Game::MenuList>();
auto* newList = allocator->allocate<Game::MenuList>();
if (!newList) return;
newList->menus = allocator->allocateArray<Game::menuDef_t*>(menus.size());
@ -35,7 +35,7 @@ namespace Assets
}
void IMenuList::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
{
Game::MenuList *asset = header.menuList;
auto* asset = header.menuList;
for (int i = 0; i < asset->menuCount; ++i)
{
@ -51,7 +51,7 @@ namespace Assets
Utils::Stream* buffer = builder->getBuffer();
Game::MenuList* asset = header.menuList;
Game::MenuList* dest = buffer->dest<Game::MenuList>();
auto* dest = buffer->dest<Game::MenuList>();
buffer->save(asset);
@ -67,7 +67,7 @@ namespace Assets
{
buffer->align(Utils::Stream::ALIGN_4);
Game::menuDef_t **destMenus = buffer->dest<Game::menuDef_t*>();
auto** destMenus = buffer->dest<Game::menuDef_t*>();
buffer->saveArray(asset->menus, asset->menuCount);
for (int i = 0; i < asset->menuCount; ++i)

View File

@ -11,7 +11,7 @@ namespace Assets
// load from disk
auto menus = Components::Menus::LoadMenu(Utils::String::VA("ui_mp/%s.menu", name.data()));
if (menus.size() == 0) return;
if (menus.empty()) return;
if (menus.size() > 1) Components::Logger::Print("Menu '{}' on disk has more than one menudef in it. Only saving the first one\n", name);
header->menu = menus[0].second;

View File

@ -166,6 +166,13 @@ namespace Components
}
}
if (!menu->window.name)
{
allocator->free(menu->items);
allocator->free(menu);
return nullptr;
}
Menus::OverrideMenu(menu);
Menus::RemoveMenu(menu->window.name);
Menus::MenuList[menu->window.name] = menu;

View File

@ -265,8 +265,10 @@ namespace Components
if (asset->type != type) continue;
const char* assetName = Game::DB_GetXAssetName(asset);
if (assetName[0] == ',') ++assetName;
const auto* assetName = Game::DB_GetXAssetName(asset);
if (!assetName) return -1;
if (assetName[0] == ',' && assetName[1] != '\0') ++assetName;
else return -1;
if (this->getAssetName(type, assetName) == name)
{