fix(Core): check spell info and prevent crash (#6454)

This commit is contained in:
Francesco Borzì
2021-06-20 19:52:44 +02:00
committed by GitHub
parent 08e205d44b
commit 36a6d04156
2 changed files with 22 additions and 1 deletions

View File

@@ -10,6 +10,7 @@
// For static or at-server-startup loaded spell data
#include "Common.h"
#include "Log.h"
#include "SharedDefines.h"
#include "Unit.h"
@@ -692,6 +693,22 @@ public:
ASSERT(spellInfo);
return spellInfo;
}
// use this instead of AssertSpellInfo to have the problem logged instead of crashing the server
SpellInfo const* CheckSpellInfo(uint32 spellId) const
{
if (spellId >= GetSpellInfoStoreSize())
{
LOG_ERROR("server", "spellId %u is not lower than GetSpellInfoStoreSize() (%u)", spellId, GetSpellInfoStoreSize());
return nullptr;
}
SpellInfo const* spellInfo = mSpellInfoMap[spellId];
if (!spellInfo)
{
LOG_ERROR("server", "spellId %u has invalid spellInfo", spellId);
return nullptr;
}
return spellInfo;
}
[[nodiscard]] uint32 GetSpellInfoStoreSize() const { return mSpellInfoMap.size(); }
// Talent Additional Set