fix(Script/Commands): cs_modify crash fix (#9471)

This commit is contained in:
Cláudio Costa
2021-12-03 11:17:59 +00:00
committed by GitHub
parent 5d2f4cf0e6
commit 1b51d25c65
+5 -22
View File
@@ -485,14 +485,8 @@ public:
return false; return false;
} }
static bool CheckModifySpeed(ChatHandler* handler, char const* args, Unit* target, float& speed, float minimumBound, float maximumBound, bool checkInFlight = true) static bool CheckModifySpeed(ChatHandler* handler, float& speed, Unit* target, float minimumBound, float maximumBound, bool checkInFlight = true)
{ {
if (!*args)
{
return false;
}
speed = Acore::StringTo<float>(args).value();
if (speed > maximumBound || speed < minimumBound) if (speed > maximumBound || speed < minimumBound)
{ {
@@ -802,20 +796,10 @@ public:
return false; return false;
} }
char const* mount_cstr = strtok(const_cast<char*>(args), " "); char* token = strtok((char*)args, " ");
char const* speed_cstr = strtok(nullptr, " "); int mount = atoi(token);
float speed = atof(strtok(nullptr, " "));
if (!mount_cstr)
{
return false;
}
if (!speed_cstr)
{
speed_cstr = "1";
}
uint32 mount = Acore::StringTo<uint32>(mount_cstr).value();
if (!sCreatureDisplayInfoStore.LookupEntry(mount)) if (!sCreatureDisplayInfoStore.LookupEntry(mount))
{ {
handler->SendSysMessage(LANG_NO_MOUNT); handler->SendSysMessage(LANG_NO_MOUNT);
@@ -837,8 +821,7 @@ public:
return false; return false;
} }
float speed = 0.f; if (!CheckModifySpeed(handler, speed, target, 0.1f, 50.0f))
if (!CheckModifySpeed(handler, speed_cstr, target, speed, 0.1f, 50.0f))
{ {
return false; return false;
} }