mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 18:52:22 +00:00
Added some nullptr checks for ItemInst* in a few places (tradeskills.cpp - particularly augments - needs a better review)
This commit is contained in:
+10
-8
@@ -1186,13 +1186,13 @@ int16 Inventory::_HasItem(std::map<int16, ItemInst*>& bucket, uint32 item_id, ui
|
||||
|
||||
for (itb = inst->_begin(); itb != inst->_end(); ++itb) {
|
||||
ItemInst* baginst = itb->second;
|
||||
if (baginst->GetID() == item_id) {
|
||||
if (baginst && baginst->GetID() == item_id) {
|
||||
quantity_found += (baginst->GetCharges() <= 0) ? 1 : baginst->GetCharges();
|
||||
if (quantity_found >= quantity)
|
||||
return Inventory::CalcSlotId(it->first, itb->first);
|
||||
}
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
if (baginst->GetAugmentItemID(i) == item_id && quantity <= 1)
|
||||
if (baginst && baginst->GetAugmentItemID(i) == item_id && quantity <= 1)
|
||||
return legacy::SLOT_AUGMENT; // Only one augment per slot.
|
||||
}
|
||||
}
|
||||
@@ -1230,13 +1230,13 @@ int16 Inventory::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint8 quantity)
|
||||
|
||||
for (itb = inst->_begin(); itb != inst->_end(); ++itb) {
|
||||
ItemInst* baginst = itb->second;
|
||||
if (baginst->GetID() == item_id) {
|
||||
if (baginst && baginst->GetID() == item_id) {
|
||||
quantity_found += (baginst->GetCharges() <= 0) ? 1 : baginst->GetCharges();
|
||||
if (quantity_found >= quantity)
|
||||
return Inventory::CalcSlotId(MainCursor, itb->first);
|
||||
}
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
if (baginst->GetAugmentItemID(i) == item_id && quantity <= 1)
|
||||
if (baginst && baginst->GetAugmentItemID(i) == item_id && quantity <= 1)
|
||||
return legacy::SLOT_AUGMENT; // Only one augment per slot.
|
||||
}
|
||||
|
||||
@@ -1330,7 +1330,7 @@ int16 Inventory::_HasItemByLoreGroup(std::map<int16, ItemInst*>& bucket, uint32
|
||||
if (inst->GetItem()->LoreGroup == loregroup)
|
||||
return it->first;
|
||||
|
||||
ItemInst* Aug;
|
||||
ItemInst* Aug = nullptr;
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
Aug = inst->GetAugment(i);
|
||||
if (Aug && Aug->GetItem()->LoreGroup == loregroup)
|
||||
@@ -1345,7 +1345,7 @@ int16 Inventory::_HasItemByLoreGroup(std::map<int16, ItemInst*>& bucket, uint32
|
||||
if (baginst && baginst->IsType(ItemClassCommon) && baginst->GetItem()->LoreGroup == loregroup)
|
||||
return Inventory::CalcSlotId(it->first, itb->first);
|
||||
|
||||
ItemInst* Aug2;
|
||||
ItemInst* Aug2 = nullptr;
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
Aug2 = baginst->GetAugment(i);
|
||||
if (Aug2 && Aug2->GetItem()->LoreGroup == loregroup)
|
||||
@@ -1373,7 +1373,7 @@ int16 Inventory::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup)
|
||||
if (inst->GetItem()->LoreGroup == loregroup)
|
||||
return MainCursor;
|
||||
|
||||
ItemInst* Aug;
|
||||
ItemInst* Aug = nullptr;
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
Aug = inst->GetAugment(i);
|
||||
if (Aug && Aug->GetItem()->LoreGroup == loregroup)
|
||||
@@ -1389,7 +1389,7 @@ int16 Inventory::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup)
|
||||
return Inventory::CalcSlotId(MainCursor, itb->first);
|
||||
|
||||
|
||||
ItemInst* Aug2;
|
||||
ItemInst* Aug2 = nullptr;
|
||||
for (int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
Aug2 = baginst->GetAugment(i);
|
||||
if (Aug2 && Aug2->GetItem()->LoreGroup == loregroup)
|
||||
@@ -1719,6 +1719,8 @@ void ItemInst::ClearByFlags(byFlagSetting is_nodrop, byFlagSetting is_norent)
|
||||
end = m_contents.end();
|
||||
for (; cur != end;) {
|
||||
ItemInst* inst = cur->second;
|
||||
if (inst == nullptr)
|
||||
continue;
|
||||
const Item_Struct* item = inst->GetItem();
|
||||
del = cur;
|
||||
++cur;
|
||||
|
||||
+28
-1
@@ -177,6 +177,7 @@ bool SharedDatabase::SaveInventory(uint32 char_id, const ItemInst* inst, int16 s
|
||||
}
|
||||
|
||||
bool SharedDatabase::UpdateInventorySlot(uint32 char_id, const ItemInst* inst, int16 slot_id) {
|
||||
// need to check 'inst' argument for valid pointer
|
||||
|
||||
uint32 augslot[EmuConstants::ITEM_COMMON_SIZE] = { NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM };
|
||||
if (inst->IsType(ItemClassCommon))
|
||||
@@ -221,6 +222,7 @@ bool SharedDatabase::UpdateInventorySlot(uint32 char_id, const ItemInst* inst, i
|
||||
}
|
||||
|
||||
bool SharedDatabase::UpdateSharedBankSlot(uint32 char_id, const ItemInst* inst, int16 slot_id) {
|
||||
// need to check 'inst' argument for valid pointer
|
||||
|
||||
uint32 augslot[EmuConstants::ITEM_COMMON_SIZE] = { NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM, NO_ITEM };
|
||||
if (inst->IsType(ItemClassCommon))
|
||||
@@ -430,7 +432,7 @@ bool SharedDatabase::GetSharedBank(uint32 id, Inventory* inv, bool is_charid) {
|
||||
int16 put_slot_id = INVALID_INDEX;
|
||||
|
||||
ItemInst* inst = CreateBaseItem(item, charges);
|
||||
if (item->ItemClass == ItemClassCommon) {
|
||||
if (inst && item->ItemClass == ItemClassCommon) {
|
||||
for(int i = AUG_BEGIN; i < EmuConstants::ITEM_COMMON_SIZE; i++) {
|
||||
if (aug[i]) {
|
||||
inst->PutAugment(this, i, aug[i]);
|
||||
@@ -527,6 +529,9 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
|
||||
|
||||
ItemInst* inst = CreateBaseItem(item, charges);
|
||||
|
||||
if (inst == nullptr)
|
||||
continue;
|
||||
|
||||
if(row[11]) {
|
||||
std::string data_str(row[11]);
|
||||
std::string idAsString;
|
||||
@@ -637,6 +642,10 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
|
||||
continue;
|
||||
|
||||
ItemInst* inst = CreateBaseItem(item, charges);
|
||||
|
||||
if (inst == nullptr)
|
||||
continue;
|
||||
|
||||
inst->SetAttuned(instnodrop);
|
||||
|
||||
if(row[11]) {
|
||||
@@ -1195,9 +1204,16 @@ ItemInst* SharedDatabase::CreateItem(uint32 item_id, int16 charges, uint32 aug1,
|
||||
{
|
||||
const Item_Struct* item = nullptr;
|
||||
ItemInst* inst = nullptr;
|
||||
|
||||
item = GetItem(item_id);
|
||||
if (item) {
|
||||
inst = CreateBaseItem(item, charges);
|
||||
|
||||
if (inst == nullptr) {
|
||||
LogFile->write(EQEMuLog::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateItem()");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inst->PutAugment(this, 0, aug1);
|
||||
inst->PutAugment(this, 1, aug2);
|
||||
inst->PutAugment(this, 2, aug3);
|
||||
@@ -1217,6 +1233,12 @@ ItemInst* SharedDatabase::CreateItem(const Item_Struct* item, int16 charges, uin
|
||||
ItemInst* inst = nullptr;
|
||||
if (item) {
|
||||
inst = CreateBaseItem(item, charges);
|
||||
|
||||
if (inst == nullptr) {
|
||||
LogFile->write(EQEMuLog::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateItem()");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inst->PutAugment(this, 0, aug1);
|
||||
inst->PutAugment(this, 1, aug2);
|
||||
inst->PutAugment(this, 2, aug3);
|
||||
@@ -1242,6 +1264,11 @@ ItemInst* SharedDatabase::CreateBaseItem(const Item_Struct* item, int16 charges)
|
||||
|
||||
inst = new ItemInst(item, charges);
|
||||
|
||||
if (inst == nullptr) {
|
||||
LogFile->write(EQEMuLog::Error, "Error: valid item data returned a null reference for ItemInst creation in SharedDatabase::CreateBaseItem()");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if(item->CharmFileID != 0 || (item->LoreGroup >= 1000 && item->LoreGroup != -1)) {
|
||||
inst->Initialize(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user