[Crash] Fix Crash with #summon (#3618)

# Notes
- Not setting target to a default of `nullptr` or in this case `c` gave undefined behavior.
This commit is contained in:
Alex King 2023-10-13 21:12:01 -04:00 committed by GitHub
parent ad0b5d6a1c
commit 9884c442e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@ void command_summon(Client *c, const Seperator *sep)
return; return;
} }
Mob* target; Mob* t = c;
if (arguments == 1) { if (arguments == 1) {
std::string character_name = sep->arg[1]; std::string character_name = sep->arg[1];
@ -33,7 +33,7 @@ void command_summon(Client *c, const Seperator *sep)
auto search_client = entity_list.GetClientByName(character_name.c_str()); auto search_client = entity_list.GetClientByName(character_name.c_str());
if (search_client) { if (search_client) {
target = search_client->CastToMob(); t = search_client->CastToMob();
} else { } else {
if (!worldserver.Connected()) { if (!worldserver.Connected()) {
c->Message(Chat::White, "World server is currently disconnected."); c->Message(Chat::White, "World server is currently disconnected.");
@ -56,15 +56,15 @@ void command_summon(Client *c, const Seperator *sep)
return; return;
} }
} else if (c->GetTarget()) { } else if (c->GetTarget()) {
target = c->GetTarget(); t = c->GetTarget();
} }
if (c == target) { if (c == t) {
c->Message(Chat::White, "You cannot summon yourself."); c->Message(Chat::White, "You cannot summon yourself.");
return; return;
} }
if (!target) { if (!t) {
c->Message(Chat::White, "You must have a target to summon."); c->Message(Chat::White, "You must have a target to summon.");
return; return;
} }
@ -73,7 +73,7 @@ void command_summon(Client *c, const Seperator *sep)
Chat::White, Chat::White,
fmt::format( fmt::format(
"Summoning {} to {:.2f}, {:.2f}, {:.2f} in {} ({}).", "Summoning {} to {:.2f}, {:.2f}, {:.2f} in {} ({}).",
c->GetTargetDescription(target), c->GetTargetDescription(t),
c->GetX(), c->GetX(),
c->GetY(), c->GetY(),
c->GetZ(), c->GetZ(),
@ -82,8 +82,8 @@ void command_summon(Client *c, const Seperator *sep)
).c_str() ).c_str()
); );
if (target->IsClient()) { if (t->IsClient()) {
target->CastToClient()->MovePC( t->CastToClient()->MovePC(
zone->GetZoneID(), zone->GetZoneID(),
zone->GetInstanceID(), zone->GetInstanceID(),
c->GetX(), c->GetX(),
@ -96,10 +96,10 @@ void command_summon(Client *c, const Seperator *sep)
return; return;
} }
target->GMMove(c->GetPosition()); t->GMMove(c->GetPosition());
if (target->IsNPC()) { if (t->IsNPC()) {
target->CastToNPC()->SaveGuardSpot(glm::vec4(0.0f)); t->CastToNPC()->SaveGuardSpot(glm::vec4(0.0f));
} }
} }