Core/Creature: fix integer overflow in Creature::Update leading to endless thrashing of characters database

Closes #19182
This commit is contained in:
ariel- authored and Aokromes committed 2017-04-14 13:45:57 +02:00
1 parent ed95f9249b
commit 0d6c2978ae
1 file changed
+12 -1
+12 -1
View File
@@ -531,7 +531,18 @@ void Creature::Update(uint32 diff)
if (targetGuid == dbtableHighGuid) // if linking self, never respawn (check delayed to next day)
SetRespawnTime(DAY);
else
m_respawnTime = (now > linkedRespawntime ? now : linkedRespawntime) + urand(5, MINUTE); // else copy time from master and add a little
{
// else copy time from master and add a little
time_t baseRespawnTime = std::max(linkedRespawntime, now);
time_t const offset = urand(5, MINUTE);
// linked guid can be a boss, uses std::numeric_limits<time_t>::max to never respawn in that instance
// we shall inherit it instead of adding and causing an overflow
if (baseRespawnTime <= std::numeric_limits<time_t>::max() - offset)
m_respawnTime = baseRespawnTime + offset;
else
m_respawnTime = std::numeric_limits<time_t>::max();
}
SaveRespawnTime(); // also save to DB immediately
}
}