From e3cce0949e4fb4e97d423b81b8d7d933cbe8eb93 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 17 May 2020 17:24:47 +0200 Subject: [PATCH] Replace condition that may lead to UB by assert If mPackages is empty it means package is a pointer to a deleted object at line . We can assume it couldn't happen because execute is always called next for this object at line 289. --- apps/openmw/mwmechanics/aisequence.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwmechanics/aisequence.cpp b/apps/openmw/mwmechanics/aisequence.cpp index 5f3931fcf..201701634 100644 --- a/apps/openmw/mwmechanics/aisequence.cpp +++ b/apps/openmw/mwmechanics/aisequence.cpp @@ -265,16 +265,15 @@ void AiSequence::execute (const MWWorld::Ptr& actor, CharacterController& charac } } - if (!mPackages.empty()) - { - if (nearestDist < std::numeric_limits::max() && mPackages.begin() != itActualCombat) - { - // move combat package with nearest target to the front - mPackages.splice(mPackages.begin(), mPackages, itActualCombat); - } + assert(!mPackages.empty()); - package = mPackages.front(); + if (nearestDist < std::numeric_limits::max() && mPackages.begin() != itActualCombat) + { + // move combat package with nearest target to the front + mPackages.splice(mPackages.begin(), mPackages, itActualCombat); } + + package = mPackages.front(); } try