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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -485,14 +485,8 @@ public:
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)
{
@ -802,20 +796,10 @@ public:
return false;
}
char const* mount_cstr = strtok(const_cast<char*>(args), " ");
char const* speed_cstr = strtok(nullptr, " ");
char* token = strtok((char*)args, " ");
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))
{
handler->SendSysMessage(LANG_NO_MOUNT);
@ -837,8 +821,7 @@ public:
return false;
}
float speed = 0.f;
if (!CheckModifySpeed(handler, speed_cstr, target, speed, 0.1f, 50.0f))
if (!CheckModifySpeed(handler, speed, target, 0.1f, 50.0f))
{
return false;
}