Fix some potential null pointer dereferences

I don't think there were any instances of these causing problems
but it's better to be safe than sorry.
This commit is contained in:
Michael Cook (mackal) 2014-01-14 02:38:49 -05:00
parent 4216627604
commit 53765ebc62

View File

@ -648,31 +648,31 @@ void QuestManager::repopzone() {
void QuestManager::settarget(const char *type, int target_id) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
Mob* tmp = nullptr;
if (!strcasecmp(type,"npctype")) {
if (!strcasecmp(type,"npctype"))
tmp = entity_list.GetMobByNpcTypeID(target_id);
}
else if (!strcasecmp(type, "entity")) {
else if (!strcasecmp(type, "entity"))
tmp = entity_list.GetMob(target_id);
}
if(tmp != nullptr) {
if (tmp != nullptr)
owner->SetTarget(tmp);
}
}
void QuestManager::follow(int entity_id, int distance) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
owner->SetFollowID(entity_id);
owner->SetFollowDistance(distance * distance);
}
void QuestManager::sfollow() {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (owner == nullptr || !owner->IsNPC())
return;
owner->SetFollowID(0);
}
@ -1086,25 +1086,26 @@ void QuestManager::setallskill(int value) {
void QuestManager::attack(const char *client_name) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
Client* getclient = entity_list.GetClientByName(client_name);
if(getclient && owner->IsAttackAllowed(getclient)) {
if (getclient && owner->IsAttackAllowed(getclient))
owner->AddToHateList(getclient,1);
} else {
else
owner->Say("I am unable to attack %s.", client_name);
}
}
void QuestManager::attacknpc(int npc_entity_id) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
Mob *it = entity_list.GetMob(npc_entity_id);
if(it && owner->IsAttackAllowed(it)) {
if (it && owner->IsAttackAllowed(it)) {
owner->AddToHateList(it,1);
} else {
if(it)
if (it)
owner->Say("I am unable to attack %s.", it->GetName());
else
owner->Say("I am unable to locate NPC entity %i", npc_entity_id);
@ -1113,13 +1114,14 @@ void QuestManager::attacknpc(int npc_entity_id) {
void QuestManager::attacknpctype(int npc_type_id) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
Mob *it = entity_list.GetMobByNpcTypeID(npc_type_id);
if(it && owner->IsAttackAllowed(it)) {
if (it && owner->IsAttackAllowed(it)) {
owner->AddToHateList(it,1);
} else {
if(it)
if (it)
owner->Say("I am unable to attack %s.", it->GetName());
else
owner->Say("I am unable to locate NPC type %i", npc_type_id);
@ -1176,7 +1178,7 @@ void QuestManager::CreateGuild(const char *guild_name, const char *leader) {
uint32 tmp = guild_mgr.FindGuildByLeader(cid);
if (tmp != GUILD_NONE) {
sprintf(hString, "Guild Creation: Error: %s already is the leader of DB# %i '%s'.", leader, tmp, guild_mgr.GetGuildName(tmp));
sprintf(hString, "Guild Creation: Error: %s already is the leader of DB# %u '%s'.", leader, tmp, guild_mgr.GetGuildName(tmp));
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", hString);
}
else {
@ -1184,7 +1186,7 @@ void QuestManager::CreateGuild(const char *guild_name, const char *leader) {
if (gid == GUILD_NONE)
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", "Guild Creation: Guild creation failed");
else {
sprintf(hString, "Guild Creation: Guild created: Leader: %i, number %i: %s", cid, gid, leader);
sprintf(hString, "Guild Creation: Guild created: Leader: %u, number %u: %s", cid, gid, leader);
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", hString);
if(!guild_mgr.SetGuild(cid, gid, GUILD_LEADER))
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", "Unable to set guild leader's guild in the database. Your going to have to run #guild set");
@ -1200,12 +1202,15 @@ void QuestManager::settime(uint8 new_hour, uint8 new_min) {
void QuestManager::itemlink(int item_id) {
QuestManagerCurrentQuestVars();
const ItemInst* inst = database.CreateItem(item_id);
char* link = 0;
if (initiator->MakeItemLink(link, inst))
initiator->Message(0, "%s tells you, %c%s%s%c", owner->GetCleanName(), 0x12, link, inst->GetItem()->Name, 0x12);
safe_delete_array(link);
safe_delete(inst);
if (initiator) {
const ItemInst* inst = database.CreateItem(item_id);
char* link = 0;
if (initiator->MakeItemLink(link, inst))
initiator->Message(0, "%s tells you, %c%s%s%c", owner->GetCleanName(),
0x12, link, inst->GetItem()->Name, 0x12);
safe_delete_array(link);
safe_delete(inst);
}
}
void QuestManager::signalwith(int npc_id, int signal_id, int wait_ms) {
@ -1486,36 +1491,41 @@ void QuestManager::rebind(int zoneid, float x, float y, float z) {
void QuestManager::start(int32 wp) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
owner->CastToNPC()->AssignWaypoints(wp);
}
void QuestManager::stop() {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
owner->CastToNPC()->StopWandering();
}
void QuestManager::pause(int duration) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
owner->CastToNPC()->PauseWandering(duration);
}
void QuestManager::moveto(float x, float y, float z, float h, bool saveguardspot) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
owner->CastToNPC()->MoveTo(x, y, z, h, saveguardspot);
}
void QuestManager::resume() {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
owner->CastToNPC()->ResumeWandering();
}
@ -1539,22 +1549,21 @@ void QuestManager::addldonloss(int32 losses, uint32 theme) {
void QuestManager::setnexthpevent(int at) {
QuestManagerCurrentQuestVars();
owner->SetNextHPEvent( at );
if (owner)
owner->SetNextHPEvent(at);
}
void QuestManager::setnextinchpevent(int at) {
QuestManagerCurrentQuestVars();
owner->SetNextIncHPEvent( at );
if (owner)
owner->SetNextIncHPEvent(at);
}
void QuestManager::respawn(int npc_type, int grid) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
//char tempa[100];
float x,y,z,h;
if ( !owner )
return;
x = owner->GetX();
y = owner->GetY();
@ -1581,7 +1590,7 @@ void QuestManager::respawn(int npc_type, int grid) {
void QuestManager::set_proximity(float minx, float maxx, float miny, float maxy, float minz, float maxz) {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if (!owner || !owner->IsNPC())
return;
entity_list.AddProximity(owner->CastToNPC());
@ -1596,8 +1605,9 @@ void QuestManager::set_proximity(float minx, float maxx, float miny, float maxy,
void QuestManager::clear_proximity() {
QuestManagerCurrentQuestVars();
if(!owner->IsNPC())
if(!owner || !owner->IsNPC())
return;
entity_list.RemoveProximity(owner->GetID());
safe_delete(owner->CastToNPC()->proximity);
}
@ -1676,7 +1686,7 @@ void QuestManager::toggle_spawn_event(int event_id, bool enable, bool reset_base
bool QuestManager::has_zone_flag(int zone_id) {
QuestManagerCurrentQuestVars();
return(initiator->HasZoneFlag(zone_id));
return initiator ? initiator->HasZoneFlag(zone_id) : false;
}
void QuestManager::set_zone_flag(int zone_id) {
@ -2757,7 +2767,7 @@ void QuestManager::enabletitle(int titleset) {
bool QuestManager::checktitle(int titleset) {
QuestManagerCurrentQuestVars();
return initiator->CheckTitle(titleset);
return initiator ? initiator->CheckTitle(titleset) : false;
}
void QuestManager::removetitle(int titleset) {