aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-04-11 23:23:52 -0300
committerariel- <ariel-@users.noreply.github.com>2017-04-11 23:23:52 -0300
commit66755eecf117d21504b13a86410aa01cfc44c3ba (patch)
treefeba4d3b914d1c37553e6bda8527156d12d63539 /src
parent5e0485178de0ab794c72d845e331559171301b22 (diff)
Core/Creature: fix integer overflow in Creature::Update leading to endless thrashing of characters database
Closes #19182
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 42234afb7fc..55c6365d109 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -600,7 +600,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
}
}