Skip to content

Commit

Permalink
ItemManager: Fix wrap overflow in item count log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed Apr 6, 2024
1 parent 251389d commit 513a90c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/ItemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,12 @@ void ItemManager::loadItems(const std::string& filename) {

item->updateLevelScaling();
}
Utils::logInfo("ItemManager: Item IDs = %zu reserved / %zu allocated / %zu empty / %zu bytes used", items.size()-1, count_allocated, items.size()-1-count_allocated, (sizeof(Item*) * items.size()) + (sizeof(Item) * count_allocated));

size_t item_count = items.size() - 1;
if (items.empty())
item_count = 0;

Utils::logInfo("ItemManager: Item IDs = %zu reserved / %zu allocated / %zu empty / %zu bytes used", item_count, count_allocated, item_count-count_allocated, (sizeof(Item*) * items.size()) + (sizeof(Item) * count_allocated));

if (eset->loot.extended_items_offset < items.size()) {
eset->loot.extended_items_offset = items.size();
Expand Down Expand Up @@ -784,7 +789,12 @@ void ItemManager::loadSets(const std::string& filename) {
else
count_allocated++;
}
Utils::logInfo("ItemManager: Item Set IDs = %zu reserved / %zu allocated / %zu empty / %zu bytes used", item_sets.size()-1, count_allocated, item_sets.size()-1-count_allocated, (sizeof(ItemSet*) * item_sets.size()) + (sizeof(ItemSet) * count_allocated));

size_t item_set_count = item_sets.size() - 1;
if (item_sets.empty())
item_set_count = 0;

Utils::logInfo("ItemManager: Item Set IDs = %zu reserved / %zu allocated / %zu empty / %zu bytes used", item_set_count, count_allocated, item_set_count-count_allocated, (sizeof(ItemSet*) * item_sets.size()) + (sizeof(ItemSet) * count_allocated));
}

void ItemManager::parseBonus(BonusData& bdata, FileParser& infile) {
Expand Down Expand Up @@ -1665,6 +1675,9 @@ void ItemManager::loadExtendedItems(const std::string& filename) {
item->updateLevelScaling();
}
size_t extended_item_count = items.size() - eset->loot.extended_items_offset;
if (items.size() > eset->loot.extended_items_offset)
extended_item_count = 0;

Utils::logInfo("ItemManager: Extended Item IDs = %zu reserved / %zu allocated / %zu empty / %zu bytes used", extended_item_count, count_allocated, extended_item_count-count_allocated, (sizeof(Item*) * extended_item_count) + (sizeof(Item) * count_allocated));
}

Expand Down

0 comments on commit 513a90c

Please sign in to comment.